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?
We can set different borders like LineBorder, BevelBorder, EtchcedBorder, EmptyBorder, TitledBorder, etc to JButton using the setBorder() method of JComponent class.
By default, we can create a JButton with a text and also can change the text of a JButton by input some text in the text field and click on the button, it will call the actionPerformed() method of ActionListener interface and set an updated text in a button by calling setText(textField.
The JButton class is used to create a labeled button that has platform independent implementation. The application result in some action when the button is pushed. It inherits AbstractButton class.
JButton class provided by Swing is totally different from Button which is provided by AWT. It is used to add platform independent button in swing application. Swing buttons are extended from the AbstractButton class that is derived from JComponent.
JButton accepts HTML, so for the line break to work use:
JButton.setText("<html>fnord<br />foo</html>");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With