Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text area text automatically go to the next line when line is finished?

This is my code for text field. It is not changing the line when the line ends, but continues to go on, making the frame look weird.

I tried to use a scroll pane, but it did not help me.

JTextArea TextArea = new JTextArea(7,10);
gridConstraints.gridx = 0;
gridConstraints.gridy = 0;
TextPanel.add(TextArea, gridConstraints);
TextArea.setEditable(true); 
like image 585
akki0996 Avatar asked Mar 09 '13 02:03

akki0996


People also ask

How do I get text to automatically go to the next line?

To do this, (1) select the text cell and in the Formula Bar, (2) position the cursor where you want to split the text (after the comma), and press ALT + ENTER on the keyboard. As a result, the text in cell B2 now starts on the next line. Note that the wrap text option is automatically turned on.

Which character defines a new line in the textArea?

Talking specifically about textareas in web forms, for all textareas, on all platforms, \r\n will work.

How to set text area in java?

The following code creates and initializes the text area: textArea = new JTextArea(5, 20); JScrollPane scrollPane = new JScrollPane(textArea); textArea. setEditable(false); The two arguments to the JTextArea constructor are hints as to the number of rows and columns, respectively, that the text area should display.


1 Answers

Without line & word wrapping, the size of a JTextArea will grow beyond its original size. You could call:

textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);

Side notes:

  • JTextArea are typically placed in JScollPane containers to facilitate scrolling.
  • Java naming conventions indicate that variables start with a lowercase letter, making TextArea textArea
like image 118
Reimeus Avatar answered Oct 28 '22 08:10

Reimeus