Problem with multi-line JTextField

后端 未结 3 413
自闭症患者
自闭症患者 2020-12-04 02:32

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 JText

相关标签:
3条回答
  • 2020-12-04 02:48

    You can't get multi-line behavior on single-line JTextField,

    use JTextArea instead

    info:

    http://answers.yahoo.com/question/index?qid=20080405030738AAJcKjU
    http://download.oracle.com/javase/6/docs/api/javax/swing/JTextArea.html

    0 讨论(0)
  • 2020-12-04 02:51

    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)

    0 讨论(0)
  • 2020-12-04 03:09
    JTextArea taText = new JTextArea();
    taText.setText("\tHI\nMY name\nis Raku");
    
    0 讨论(0)
提交回复
热议问题