Append text in JLabel

前端 未结 2 1290
囚心锁ツ
囚心锁ツ 2020-12-11 09:19

How would I go about achieving the effect of JTextArea with JLabel?

I want the output to be displayed every time the button is clicked on the next line down instead

相关标签:
2条回答
  • 2020-12-11 09:27

    You can do that as follows,

    label.setText(label.getText() + "text u want to append");
    

    on each event.

    0 讨论(0)
  • 2020-12-11 09:33
    1. Use HTML formatting in the label by starting the text with prefix <html><body> (possibly add some in-line styles in the body opening element).
    2. Add each line, ending with <br> or <p> (or <li> if adding <ul><li> to the prefix).

    See also How to Use HTML in Swing Components. For such gems as..

    HTML Button

    0 讨论(0)
提交回复
热议问题