JButton and JField labels/text?

2020-04-10 04:02发布

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

2条回答
太酷不给撩
2楼-- · 2020-04-10 04:51

Use HTML

JButton button = new JButton("<html><body>line 1 <br /> line 2</body></html>");
查看更多
够拽才男人
3楼-- · 2020-04-10 04:56

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

查看更多
登录 后发表回答