How to add multi-line label on a Java GUI?

和自甴很熟 提交于 2019-12-10 20:02:00

问题


I have made a java swing GUI. Now I want to display a static message on that but the message is multi-line and the JLabel is single line.

How can I display that message?

Is there any property of JLabel which we can set to display the multiple line message?

Will I have to use several JLabels for multiple lines?

Is there any other way I can display that message?


回答1:


How to Use HTML in Swing Components

Displaying Multi Line Text




回答2:


You can do

JLabel l = new JLabel("<html><p>Hello World! blah blah blah</p></html>");

and it will automatically wrap it where appropriate.



来源:https://stackoverflow.com/questions/1627048/how-to-add-multi-line-label-on-a-java-gui

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