多行JTextField问题 [英] Problem with multi-line JTextField
本文介绍了多行JTextField问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 JTextField
,并且需要有3行,例如:
I have a JTextField
and need to have 3 lines in it, such as these:
HI
MY name
is mehdi
如何我可以在 JTextField
中设置文本吗?我试过 \ n
,但它没有用。
How can I set the text in a JTextField
? I tried \n
, but it didn't work.
推荐答案
1:JTextField不支持多行。你想要的是一个JTextArea
1 : JTextField does not support multiline. what you want is a JTextArea
2:所有系统上的换行符都不一样,你可能需要使用\\\ n
如果您正在运行Windows。从Java 7开始,有 System.LineSeparator
来解决这个问题。
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.
(参见 Oracle文档)
这篇关于多行JTextField问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文