Java JButton set HTML text for button label

Description

Java JButton set HTML text for button label


import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {
    super("JButton");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());

    JButton closeButton1 = new JButton("<html>"
        + "<center><b><u>D</u>isable</b><br>"
        + "<font color=#ffffdd>middle button</font></html>");

    getContentPane().add(closeButton1);/*w ww  . j  a  v  a 2 s  .co  m*/
  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related