How do we changeline in a label?

社会主义新天地 提交于 2019-12-01 10:47:15

问题


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);

I tried the above code but it does not work..How do I change line in a string ?


回答1:


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 ...




回答2:


Use this string

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


来源:https://stackoverflow.com/questions/4546204/how-do-we-changeline-in-a-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!