Setting the default button : JRootPane « Swing « Java Tutorial






  1. Dark border
  2. pressing the Enter key to trigger button's event
Setting the default button
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;

public class SettingDefaultButtonJRootPane {
  public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button4 = new JButton("AAA");
    frame.add(button4,"Center");
    frame.add(new JButton("BBB"),"South");
    JRootPane rootPane = frame.getRootPane();
    rootPane.setDefaultButton(button4);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}








14.84.JRootPane
14.84.1.JRootPane
14.84.2.Setting Window Decoration StyleSetting Window Decoration Style
14.84.3.Setting the default buttonSetting the default button
14.84.4.Interact directly with the JRootPane of a JFrame
14.84.5.Make a JFrame looks like a JDialog
14.84.6.Customizing JRootPane Look and Feel