Problem with multi-line JTextField

2019-01-12 09:54发布

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.

3条回答
爷的心禁止访问
2楼-- · 2019-01-12 10:46
forever°为你锁心
3楼-- · 2019-01-12 10:47

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)

查看更多
成全新的幸福
4楼-- · 2019-01-12 10:55
JTextArea taText = new JTextArea();
taText.setText("\tHI\nMY name\nis Raku");
查看更多
登录 后发表回答