Java Swing How to - Display HTML on JButton








Question

We would like to know how to display HTML on JButton.

Answer

import javax.swing.JButton;
import javax.swing.JOptionPane;
// w  w  w  .ja  va 2 s.co m
public class Main {
  public static void main(final String args[]) {
    String s = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
        + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button = new JButton(s);

    JOptionPane.showMessageDialog(null, button);
  }
}