New Line \n is not working in JButton.setText(“fnord\nfoo”) ; [duplicate]

混江龙づ霸主 提交于 2019-12-19 16:55:25

问题


On a JButton, I want to list information on multiple lines. I tried \n as a new line character but it didn't work. The following code:

JButton.setText("fnord\nfoo") ;

will be displayed as:

fnordfoo

How do I force a line break?


回答1:


JButton accepts HTML, so for the line break to work use:

 JButton.setText("<html>fnord<br />foo</html>");


来源:https://stackoverflow.com/questions/13503280/new-line-n-is-not-working-in-jbutton-settextfnord-nfoo

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