How do we changeline in a label?

前端 未结 2 917
滥情空心
滥情空心 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= "First line
    Second line"

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

提交回复
热议问题