JFrame: setDefaultButton(JButton defaultButton) : JFrame « javax.swing « Java by API






JFrame: setDefaultButton(JButton defaultButton)

  

import java.awt.GridLayout;
import java.awt.event.KeyEvent;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;

public class MainClass {

  public static void main(String[] a) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(2, 2, 10, 10));

    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);

    JButton button2 = new JButton("warn");
    frame.add(button2);

    JButton button3 = new JButton("Warning");
    frame.add(button3);

    String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
        + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button4 = new JButton(htmlButton);
    frame.add(button4);

    JRootPane rootPane = frame.getRootPane();
    rootPane.setDefaultButton(button2);

    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.JFrame.DISPOSE_ON_CLOSE
2.JFrame.DO_NOTHING_ON_CLOSE
3.JFrame.EXIT_ON_CLOSE
4.JFrame: addComponentListener(ComponentListener l)
5.JFrame: addContainerListener(ContainerListener l)1
6.JFrame: addMouseWheelListener(MouseWheelListener l)
7.JFrame: addWindowListener(WindowListener lis)
8.JFrame: getAccessibleContext()
9.JFrame: getContentPane().getActionMap() [Bind key action to JFrame]
10.JFrame: getDefaultCloseOperation()
11.JFrame: getFontMetrics(Font font)
12.JFrame: getGlassPane()
13.JFrame: getLayeredPane()
14.JFrame: isFocusOwner()
15.JFrame: isUndecorated()
16.JFrame: processWindowEvent(WindowEvent e)
17.JFrame: setAlwaysOnTop(boolean alwaysOnTop)
18.JFrame: setBackground(Color c)
19.JFrame: setCursor(Cursor c)
20.JFrame: setDefaultButton(JButton bn) (Remove 'Enter' key stroke from JTextField)
21.JFrame: setDefaultCloseOperation(int option)
22.JFrame: setDefaultLookAndFeelDecorated(boolean b)
23.JFrame: setExtendedState(int state)
24.JFrame: setFocusable(boolean focusable)
25.JFrame: setFocusableWindowState(boolean focusableWindowState)
26.JFrame: setFocusTraversalPolicy(FocusTraversalPolicy lo)
27.JFrame: setIconImage(Image image)
28.JFrame: setJMenuBar(JMenuBar bar)
29.JFrame: setLocation(int x, int y)
30.JFrame: setLocationByPlatform(boolean locationByPlatform)
31.JFrame: setLocationRelativeTo(Component c)
32.JFrame: setMaximizedBounds(Rectangle bounds)
33.JFrame: setSize(int width, int height)
34.JFrame: setTitle(String title)
35.JFrame: setUndecorated(boolean b)
36.JFrame: setVisible(boolean visible)