Java Swing How to - Create JButton with Multiline Label using HTML








Question

We would like to know how to create JButton with Multiline Label using HTML.

Answer

import javax.swing.JButton;
import javax.swing.JOptionPane;
/*w w w . ja  v  a 2  s.c o m*/
public class Main {
  public static void main(final String args[]) {
    String label = "<html>" + "This is a" + "<br>" + "swing button" + "</html>";

    JButton button = new JButton(label);

    JOptionPane.showMessageDialog(null, button);
  }
}