Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with multi-line JTextField

I have a JTextField and need to have 3 lines in it, such as these:

HI
MY name
is mehdi

How can I set the text in a JTextField? I tried \n, but it didn't work.

like image 796
Mahdi_Nine Avatar asked Nov 28 '22 18:11

Mahdi_Nine


1 Answers

1 : JTextField does not support multiline. what you want is a JTextArea

2 : Newlines aren't the same on all systems, you might have to use "\r\n" if you are running Windows. Since Java 7, there is System.LineSeparator to solve this issue.

(see the Oracle documentation)

like image 188
Timothy Groote Avatar answered Dec 05 '22 10:12

Timothy Groote