JButton and JField labels/text?

梦想与她 提交于 2019-12-02 02:10:44

问题


I have a JButton that I would like to fill in with text that would spread in two lines, however, when I type in the test and use "\n" or "\r" I still get the text on one line.

This is the case with the elements of my jList as well.

Thanks


回答1:


Use HTML

JButton button = new JButton("<html><body>line 1 <br /> line 2</body></html>");



回答2:


Indeed, JButton admits HTML. However <body> is not really necessary:

JButton button = new JButton("<html> mylabel <br /> mylabel continues on a newline </html>");

[[ taken from New Line \n is not working in JButton.setText("fnord\nfoo") ; ]]



来源:https://stackoverflow.com/questions/7768694/jbutton-and-jfield-labels-text

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