New Line \n is not working in JButton.setText("fnord\nfoo") ;
JButton accepts HTML, so for the line break to work use:
JButton.setText("<html>fnord<br />foo</html>");
k0pernikus
I am Philipp Kretzschmar, a backend developer from Hamburg working at Demvsystem. You can find me on github. Or twitter. My main weapons of choice are: php TypeScript (I don't want to write plain JavaScript anymore) and nodejs I play around with: Java python rust I used to write some scala, but for now I don't want to go there anymore. I feel most comfortable on a unix-like system featuring a powerful bash. (This excludes MacOS.) I love to code within JetBrains's flavored IDEs, e.g. IntelliJ, PhpStorm, WebStorm and using the IdeaVim plugin and having a docker-compose stack to develop on.
Updated on November 22, 2020Comments
-
k0pernikus over 3 years
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?
-
Jakub Zaverka over 11 yearsJust don't use too much HTML in Swing labels.
-
Andrew Thompson over 11 yearsSee also Word-wrap in JButtons & Append text in JLabel.