FAQ Database Discussion Community


JScrollPane shrink/collapse on window minimize

java,swing,jscrollpane,jtextarea
I have a JScrollPane which contains a JTextArea. When the window is minimized and then restored, the JScrollPane will then collapse on itself. Note that this squish only happens if the text in the JTextArea exceeds the given width and/or height of the JTextArea (i.e., the horizontal or vertical scrollbars...

I am unable to output values into j text area

java,swing,user-interface,integer,jtextarea
I tried to create a java GUI which displays a multiplication table of a number input by the user in a text area The problem is, the results are not being displayed in the text area completely. For example if I input the number 3, only "30" is being displayed...

JTextArea show last X lines

java,line,limit,jtextarea
I want to use jTextArea as log of events for my application. I know I can redirect system.out and system.in but I want to use multiple jTextArea logs for different parts of my code. For example I want to do TCPServer log and display log for it in jTextArea. For...

JTextPane line wrap behavior

java,swing,jtextarea,jtextpane,linewrap
Recently I have been working on a Java text editor project and I would like to use a JTextPane to replace the old JTextArea in order to implement syntax highlighting. However, a JTextPane lacks methods in JTextArea (such as append(), getLineStartOffset() etc) and I want to reimplement them in my...

String append to JText Area after do other task

java,swing,sockets,append,jtextarea
public void doConnect(){ try{ statusArea.append("Starting server.....\n"); serverSocket = new ServerSocket(5555); statusArea.append("Server started.\n"); statusArea.append("Waiting for client connection....\n"); socket = serverSocket.accept(); statusArea.append("Client connected.\n"); inStream = new ObjectInputStream(socket.getInputStream()); } catch (IOException e){ e.printStackTrace(); } } All strings be appended to text area only after I start server and client connected. So I want...

How to write into JTextArea from other functions?

java,swing,jtextarea
my app works as network game, and I am getting messages from server and I wanna show them in my JTextArea. Code looks like this: public class klient extend JFrame{ ...declarations JTextArea areaText; public klient(){ setSize(600,300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("example"); setLocationRelativeTo(null); getContentPane().add(createComponents()); } public JPanel createComponents(){ JPanel mainPanel = ... .... Jpanel...

How to link two jComboBoxes together and display the data into a jtextarea?

java,swing,jcombobox,jtextarea,jlist
My question is how to link two comboboxes together. The reason being that I want the user to be able to choose a manufacturer brand and for the next combobox to display the cars linked to that manufacturer. Then I want the data to be put into a jtextarea to...

Display integer in JTextArea

java,swing,int,jtextarea
I have created a JTextArea as follows: JTextArea area = new JTextArea(20,15); add(new JScrollPane(area), BorderLayout.CENTER); I want to it to display the integer "0" when the code runs. I dont know how to add an int to the Area. I have tried the following code for that : int a=...

Copy JTextArea as “text/html” DataFlavor

java,html,swing,clipboard,jtextarea
I have a JTextArea and I am using a Highlighter to apply some syntax highlighting to some of my text as per my SSCCE below: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class SSCCE extends JFrame { public SSCCE() { final JTextArea aMain = new JTextArea(); aMain.setFont(new Font("Consolas",...

How to keep Focus on JTextField while clicking input number buttons?

java,swing,jtextfield,jtextarea
I am new to GUI stuff and am having trouble with the following problem. I have 3 JTextFields, credit card number, expiration date, and security number. I am able to input information into the fields. I also implemented the focus listener for each button. If I click it, it says...

Text area not showing up [closed]

java,swing,jtextarea
I am trying to add a simple empty field to my program, in which a user can put in his name. Trying this, no text area is visible at all. JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setSize(800, 600); JTextArea enterName1 = new JTextArea(50, 50); enterName1.setRows(20); enterName1.setColumns(1); panel.add(enterName1, BorderLayout.CENTER); enterName1.setVisible(true);...

Getting user input from JTextArea

java,oop,project,jtextarea
I'm trying to build a quiz program. I decided that users enter their answers(numbers) into a JTextArea and the result will be shown on another JTextArea after a button click however I'm having troubles. Here is partial of my code. JButton btnNewButton = new JButton("Submit!"); btnNewButton.addActionListener(new ActionListener() { public void...

Dispatching key events on JTextArea doesn't move the caret

java,swing,simulation,jtextarea
I want to simulate key presses on a JTextArea. I would use the Robot class, but the window I want to type in doesn't have focus. So I have a scenario like this: public class Test { public static void main(String[] args) { Frame frame = new Frame(); JTextArea text...

Why is my text in the jTextarea not highlighted anymore?

java,swing,highlight,jtextarea
I am making a small Swing application and have a JTextarea where I want a part of the text to be highlighted. When I start my appl. the line that I indicated to be highlighted is highlighted by the method "highlight()" public static void highlight() { uihw.getTa().setSelectionStart(indexTxt[pencil]);//uihw is the ui...

Java GUI Calculator

java,swing,user-interface,calculator,jtextarea
My JTextArea does not display and no errors or problems shows up. It's a Java GUI Calculator. Main class code: import javax.swing.JFrame; public class calulator_main{ public static void main(String[] args) { // TODO Auto-generated method stub calulator_ui frame = new calulator_ui(); frame.frame.setVisible(true); } } Calculator code: import java.awt.BorderLayout; import java.awt.FlowLayout;...

Mechanisms of setText() in JTextArea?

java,swing,jframe,jtextarea,settext
I try to show some text in my JTextArea in runtime. But when I use a loop of setText to show text in order, it only show the text of the last loop Here is my code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { for (int i=0;i<10;i++) jTextArea1.setText("Example "+i); } I want...

Moving Cursor Down a line - Java

java,eclipse,text,jtextarea
I have created a JtextArea, and after having added a piece of text to the text area, want to cursor to be moved to the next line. I.e. I append the string to the text area, and when the user starts typing into the text area, want the input to...

How can I evenly space out 2d array in JTextArea without \t?

java,matrix,formatting,jtextarea
I ran into a little problem today while I was coding. I'm no expert in java, and I'm only just starting to learn GUI, so bear with me please. I'm creating a game that involves a map that is composed of this 2D array, I've created a method to put...

Update a JTextArea dynamically depending on users JTextField values

java,swing,jtextfield,jtextarea
I have two JTextField which take numbers from users, like this: nbMuscle = new JTextField(); nbMuscle.setText("2"); and this: nbFuyard = new JTextField(); nbFuyard.setText("1"); my JTextArea() takes make an addition of both JTextField's values, like this: nbPersonnages = new JTextArea(); int nombMusc = Integer.valueOf(nbMuscle.getText()); int nombFuy = Integer.valueOf(nbFuyard.getText()); int nbTotal =...

JScrollPane Confusion

java,swing,jscrollpane,jtextarea
So, I'm attempting to add in a JScrollPane to a JTextArea so that I can scroll down, but no matter what I do, the pane does not show up. Am I in violation of some Swing stuff, or just a fail? Also, this is for a school project so I...

How can I add a long text to my fillRect?

java,swing,graphics,jtextarea
I'm working on a program that add pins to a map, the pins are are subclasses to a class that draws a triangle to the map and are clickable, and if you click it shall unfold and show different things like name, text or a picture. I've one working subclass...

TextArea with Canvas Binding to Rect

java,canvas,textarea,jtextarea,game-loop
I have the problem of this textarea not showing up when I run it. Is there any way to make it show up. BTW its getting called through the gameloop on a class that extends canvas. public void render(Graphics g){ Graphics2D g2d = (Graphics2D) g; if(!initialized) init(); try { test.requestFocus();...

JTextArea and GridBagLayout: how to avoid changing column width as we write some text?

java,swing,layout-manager,jtextarea,gridbaglayout
I would like to design a JFrame whose layout consists in 3 columns: a left column containing a text editor (I have chosen a JTextArea); center column containing a single button (JButton); a right column containing another text editor. I managed to do this using the GridBagLayout class. However, when...

Getting a position in a JTextArea and using a timer

java,swing,jtextarea
I'm working on a school project and I'm hoping if you guys could help me. I have this: JTextArea processTxt = new JTextArea(); And when I press this button, JButton sortBtn = new JButton("SORT!"); This would display this on processTxt. public void sort(String type, String order, int size) { int...

calling a method to restart if a condition is met without using a loop

java,user-interface,oop,jtextfield,jtextarea
I am working on a payroll program for school. I only two weeks into working with GUIs so my skills have a lot of room for growth. Everything works fine except for this method. I am trying to get the method to clear the JTextAreas if the number entered is...

How to get the number of character in a JTextArea?

java,swing,jtextarea
I have a JTextArea and I need to take each one of the field's characters to translate it into another. But for this purpose I need to browse in the JTextArea. So I thought of a simple loop like: for(int i = 0; i <= t.length(); i++) { ... }...

Update JTextArea text in JFrame from Custom JDialog output data or results

java,swing,jpanel,jtextarea,jdialog
I have a JTextArea inside a main layout that I want to update using a custom JDialog. Difficult to explain in words like this...so please just follow code and explanation process as outlined below: I have a JPanel that contains the JTextArea (i.e. original JTextArea - 'cancellationPolicTA') that needs to...

JTextArea with same parameters but not same size

java,jpanel,jtextarea
public UserInterface(){ super(new BorderLayout()); fc = new JFileChooser(); setComponents(); } public void setComponents(){ //top section openButton = new JButton("Charger fichier"); openButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(openButton); //left section //class panel JPanel classe = new JPanel(); classes = new JTextArea(25,15); classes.setMargin(new Insets(5,5,5,5)); classes.setEditable(false); JScrollPane classeScrollPane = new JScrollPane(classes); classe.setBorder(new TitledBorder("Classes"));...

JScrollPane not scrolling in a MigLayout

java,jscrollpane,jtextarea,miglayout
In this code I am trying to insert a JScrollPane into my panel which is using the MigLayout. import java.awt.*; import javax.swing.*; import net.miginfocom.swing.MigLayout; public class Simple2 { JFrame simpleWindow = new JFrame("Simple MCVE"); JPanel simplePanel = new JPanel(); JLabel lblTitle; JLabel lblSimple; JTextArea txtSimple; JScrollPane spSimple; GraphicsEnvironment ge =...

Java: Adding JScrollPane to JTextArea

java,swing,jscrollpane,jtextarea
I need some help adding a scroll bar to my JTextArea. The code I'm working on now seems to add the scrollbar to the frame instead of the textArea. The bar is visible, but nothing happens when text go outside the bounds of the frame. Code bellow, does not contain...

Unable to add text to JTextArea in Java from another function

java,function,static,actionlistener,jtextarea
I made a simple program in Java that contains only one text area and a button. The button is suppose to add a "text". However, it doesn't work for me. On a side note: I'm trying to keep my functions as short as possible. (I don't want a function with...

Incrementing value of an integer in JTextArea

java,swing,jbutton,actionlistener,jtextarea
I have the following code in which I have created a JTextArea and Menubar in which I have added menuItem Inc. I have coded the value of "val" = 0 , so that when the code runs and frame appears, the first thing that is seen is zero. But i...

How to output fields in an ArrayList to a JTextArea?

java,swing,user-interface,jtextarea,settext
I'm trying to do something on the lines of: someJtextArea.setText(String.valueOf( for(int i = 1; i < 0; i++) { objInstance.anArrayList.get(i).getFirstName() } )); ...

Java how to display line number on the side of text components

java,jtextarea,line-numbers,rights
I want to display line numbers in a text component. I found this link https://tips4java.wordpress.com/2009/05/23/text-component-line-number/ And it worked. But I want to display line number on the right side of textarea. How can I do it. Thank!

How can i add JLabel and JTextArea in the same space in JAVA

java,swing,jpanel,layout-manager,jtextarea
Here is the UI that I'd like to make. I'm new to UI design. Could anyone tell me which layout should i use? How to make JLabel and JTextArea stick together and make String in the JTextArea clickable? Are there better ways to realize this design. I have tried BorderLayout,...

How to make key events work on a JDialog while there is a JTextArea on it?

java,jtextarea,keyboard-events,jdialog
What I have basicly created is a JDialog which has a key event on the form. So when for example space is pressed it does something. This worked fine until I created a JTextArea on the same dialog, which is editable. When I did this I can't remove the focus...

JOptionPane with a JTextArea instead of a text field?

java,swing,user-interface,jtextarea,joptionpane
I need to grab multiple lines of input from a popup JOptionPane (or some other popup, but most of my searches direct me there, which is where I get stuck..). I am stuck at using JOptionPane.showInputDialog(null, new JTextArea(20,20)); but I want just the 20x20 area to be read to a...

Restricting access to some lines in JTextArea?

java,text,jtextarea
I wanted to make a JTextArea where the user can't erase the previous line. Just like the Command Prompt in Windows and the terminal in Linux, you can't edit previous lines. This is what I've come up with, but it doesn't seem to work, and I can only come up...

Highlight different text in jtextarea

java,swing,jtextarea
These are the following things i want to know: I want to highlight different text in jtextarea by selecting them by mouse. I also want to get all the highlighted text later. I also want to know how to remove particular highlighted line. What code can i use ?...

Outputting batch file to JTextArea

java,batch-file,jtextarea
I have some code set up that is supposedly running the batch file. I'm not sure though because it's not showing anything in the console, but when I click the JButton PING, the button holds in the click for a couple seconds so it's definitely processing something. What I need...

java Change content of JTextArea in JOptionPane with Timer

java,swing,timer,jtextarea,joptionpane
The result looks like this question: reading a log file and displaying it in jtextarea but the different is I use JOptionPane. My process is like that: User click the 'Update' button, then it will show a JOptionPane with JTextArea, and I should use Timer to get the status of...

How to set bold font style for selected text in JTextArea instance

java,swing,fonts,jtextarea
I want to set bold font style for selected text in JTextArea instance. I tried this way: textArea.getSelectedText().setFont(new Font("sansserif",Font.BOLD, 12)); But it does not work. Also I've tried JTextPane and JEditorPane instead of JTextArea but without effect. How can I do that?...

Java JTextArea dynamic column and row numbering

java,string,swing,hex,jtextarea
I've had a quick Google around, and I can't seem to find a good solution to this, mostly because I'm not sure how to describe it. Essentially, I need to display an arbitrary amount of hex characters in a JTextArea, and I'd like to have them spaced evenly, and have...

how to print 2D array in TextArea

java,jframe,jbutton,jtextarea
Hello guys I need some help I wanted to print 2D array into a JTextArea with the JButton. I have this method: public static void getMaze(){ for(int i = 0; i<rows; i++) for(int j = 0; j<columns; j++) array[i][j] = "[]"; array [i3][i4]="# "; array [i5][i6]="# "; array [i7][i8]="# ";...

Append Text to JTextArea on Multiple Lines?

java,string,swing,jtextarea
I have a string with multiple numbers, when printed out it looks something like this: 2 4 5 10 20 25 50 However, when I append the string to a JTextArea it looks like this: 24510202550 How can I make the JTextArea look like the ouput with the numbers on...

Updating jTextArea in while loop

java,swing,while-loop,jtextarea,updating
I am having a problem writing/updating the textarea. I am getting a value from the readtemp function, and i can see the result after calling the system out function, but nothing appears in the Textarea. What could be the problem? private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { URL temp; try { temp...

How to add JTextArea to JScrollPane?

java,swing,jscrollpane,jtextarea,jtextcomponent
I am trying to create a simple text editor, and I have run into a problem trying to take my JTextArea and make it scroll-able via a JScrollPane. The conventional methods I know of have not worked, so I am wondering if anyone here can help. I am not sure...

JScrollPane not displaying on JTextArea

java,swing,jscrollpane,jtextarea
The JScrollPane that I'm trying to implement isn't working. I want to add it to my JTextArea, but for some reason it doesn't want to display //JTEXTBOX textArea = new JTextArea(); textArea.setEditable(false); //JSCROLLPANE JScrollPane scroll1 = new JScrollPane(textArea); scroll1.setPreferredSize(new Dimension(200, 250)); scroll1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scroll1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); ...

Formatting Text Color In JTextArea

java,swing,colors,jtextarea
I'm redirecting the Java console output to a JTextArea that is inside of a JPanel. I'm using System.out.setOut(new PrintStream(taOutputStream)) and System.out.setErr(new PrintStream(taOutputStream))for redirecting the output. The problem I'm running into that the text is always black when it's redirected to the JPanel. I want the setErr code to be red...

Updating UI for JTextArea in Java

java,swing,user-interface,jtextarea
I'm a beginner and I've hit a bump in the road. The problem I have is that my JTextArea is not updating as my program is running. I ran a command line to see whether the value of the JTextArea is changing. It turns out that it is but on...

Getting methods to print to a TextArea in JPanel

java,swing,methods,jpanel,jtextarea
So I am working on a project for a class because I am trying to learn this lovely thing called Java. Well anyway I am trying to get some methods to print out in the TextArea in my JPanel. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class GUI_Amortization_Calculator extends JFrame...

Swing JTextArea cannot show font type and color

java,swing,jtextarea
I am developing a spam detector application using Java GUI (NetBeans). Now I have a simple user interface which includes a text area in which the user is going to paste his email in to order to check if its a spam or not, but the problem is when you...

Adding text to multiple JTextAreas in different tabs of a JTabbedPane dynamically?

java,dynamic,jtable,jtextarea,jtabbedpane
So I am dynamically adding JTextAreas to a JTabbedPane on the click of a JTable cell. I was wondering how to also set the text of the JTextArea dynamically. I was looking at trying to use getSelectedIndex() nested in getComponentAt(), but this returns a Component rather than a JTextArea so...

Adding string element to an Array Java

java,loops,jtextarea
I am trying to get a string element to print to 1 spot in an array but every time it execute it takes up all (5) spaces. Ultimately I am trying to get a JButton to assign the string value to the strArray[a] space and appear on a JTextArea Code:...