Creating a Multiline Label for a JButton Component
import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; public class Main { public static void main(String[] argv) throws Exception { String label = "<html>" + "This is a" + "<br>" + "swing button" + "</html>"; // Create an action with the label Action action = new AbstractAction(label) { // This method is called when the button is pressed public void actionPerformed(ActionEvent evt) { // Perform action } }; // Create the button JButton button = new JButton(action); } }