How do we changeline in a label?

前端 未结 2 916
滥情空心
滥情空心 2021-01-16 06:25

I have a label and when setting the text I want to change line . For instance

String str=\"first line \\n Secondline \";
JLabel label.setText(str);
<         


        
相关标签:
2条回答
  • 2021-01-16 06:47

    Swing does not uses classical line breaks. Instead, for a reason I never fully understood, it uses HTML 3.2. As a consequence, to have your text correctly displayed, yopu have to rely upon HTML content :

    String str= "<html>First line<br>Second line</html>"
    

    However, if you really want to, there are other possibilities ...

    0 讨论(0)
  • 2021-01-16 06:48

    Use this string

    String str= "<html>First line<br>Second line</html>"
    
    0 讨论(0)
提交回复
热议问题