Java Swing How to - Create JButton from text








Question

We would like to know how to create JButton from text.

Answer

//w  w  w . jav  a2  s .c o m
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class Main {
  public static void main(final String args[]) {
    JButton button = new JButton("Dog");

    JOptionPane.showMessageDialog(null, button);
  }
}