Search code examples
javainputjlabel

JLabel requires HTML for linebreaks


I'm trying to make a section of a frame where I can put some text and change this text programmatically.

Basicly it's just an area that gets text appended to it through an input field.

So far I've tried Textarea, Label and Pane but a Pane doesn't let me change the text, the Textarea is editable and the Label doesn't allow linebreaks without resorting to HTML (not desired due to variables no longer working when I do).

Is there something similar to Label that doesn't use HTML or some other element that lets me change text inside?

I just want to add text to an area on the screen that allows linebreaks.


Solution

  • You can use the JTextArea and set the editable flag to false:

      JTextArea area = new JTextArea();
      area.setEditable(false);