Example usage for javax.swing JButton setMnemonic

List of usage examples for javax.swing JButton setMnemonic

Introduction

In this page you can find the example usage for javax.swing JButton setMnemonic.

Prototype

@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic")
public void setMnemonic(int mnemonic) 

Source Link

Document

Sets the keyboard mnemonic on the current model.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JButton button = new JButton("Button");
    button.setMnemonic('B');
    JCheckBox checkBox = new JCheckBox("CheckBox");
    checkBox.setMnemonic('C');
}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Text Button");
    button.setMnemonic(KeyEvent.VK_B);

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);//from  w w  w .  j av  a 2s  .  c o  m
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MnemonicSample.java

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

    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(1, 0));

    JButton button1 = new JButton("Warning");
    button1.setMnemonic(KeyEvent.VK_W);
    content.add(button1);//from   w  ww . j av  a2  s . com

    JButton button2 = new JButton("Warning");
    button2.setMnemonic(KeyEvent.VK_H);
    content.add(button2);

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

From source file:MainClass.java

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);//from www .  j a  v  a  2 s  .  c  om

    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);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final Action printAction = new PrintHelloAction();

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);//w  w w . j  a v  a  2s . c  o  m
    JMenuItem menuItem = new JMenuItem("Print");
    KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK);
    menuItem.setAccelerator(ctrlP);
    menuItem.addActionListener(printAction);
    menu.add(menuItem);

    JButton fileButton = new JButton("About");
    fileButton.setMnemonic(KeyEvent.VK_A);
    fileButton.addActionListener(printAction);

    frame.setJMenuBar(menuBar);

    frame.add(fileButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:ScreenDump.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Action Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final Action printAction = new PrintHelloAction();

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);/*from   w  w  w . j a  v  a  2 s .  c om*/
    JMenuItem menuItem = new JMenuItem("Print");
    KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK);
    menuItem.setAccelerator(ctrlP);
    menuItem.addActionListener(printAction);
    menu.add(menuItem);

    JButton fileButton = new JButton("About");
    fileButton.setMnemonic(KeyEvent.VK_A);
    fileButton.addActionListener(printAction);

    frame.setJMenuBar(menuBar);

    Container contentPane = frame.getContentPane();
    contentPane.add(fileButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Mnemonic/Accelerator Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final Action printAction = new PrintHelloAction();

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);//from  w w w.  j  a  v  a  2 s  .c  o  m
    JMenuItem menuItem = new JMenuItem("Print");
    KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK);
    menuItem.setAccelerator(ctrlP);
    menuItem.addActionListener(printAction);
    menu.add(menuItem);

    JButton fileButton = new JButton("About");
    fileButton.setMnemonic(KeyEvent.VK_A);
    fileButton.addActionListener(printAction);

    frame.setJMenuBar(menuBar);

    frame.add(fileButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:ActionButtonSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String command = actionEvent.getActionCommand();
            System.out.println("Selected: " + command);
        }/*from   www. j ava2 s  . com*/
    };

    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(2, 2));

    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    button1.setActionCommand("First");
    button1.addActionListener(actionListener);
    content.add(button1);

    Icon warnIcon = new ImageIcon("Warn.gif");
    JButton button2 = new JButton(warnIcon);
    button2.setActionCommand("Second");
    button2.addActionListener(actionListener);
    content.add(button2);

    JButton button3 = new JButton("Warning", warnIcon);
    button3.setActionCommand("Third");
    button3.addActionListener(actionListener);
    content.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);
    button4.setActionCommand("Fourth");
    button4.addActionListener(actionListener);
    content.add(button4);

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

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

From source file:Main.java

public static void main(String args[]) {
    JButton jbtnA = new JButton("java2s.com");

    JFrame jfrm = new JFrame();
    jfrm.setSize(300, 300);//from   w w w .j  ava 2s.co  m

    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jfrm.getRootPane().setDefaultButton(jbtnA);

    jbtnA.setMnemonic(KeyEvent.VK_A);

    jbtnA.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println("Alpha pressed. Beta is enabled.");
            jbtnA.setEnabled(!jbtnA.isEnabled());
        }
    });
    jfrm.add(jbtnA);
    jfrm.setVisible(true);
}