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
Use HTML
JButton button = new JButton("<html><body>line 1 <br /> line 2</body></html>");
mario go
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