Example usage for javax.swing JButton getActionForKeyStroke

List of usage examples for javax.swing JButton getActionForKeyStroke

Introduction

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

Prototype

public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke) 

Source Link

Document

Returns the object that will perform the action registered for a given keystroke.

Usage

From source file:com.mgmtp.perfload.loadprofiles.ui.util.SwingUtils.java

/**
 * Registers the enter key a {@link JButton}.
 * //from w ww . j  av  a2  s.com
 * @param button
 *            The button
 */
public static void enterPressesWhenFocused(final JButton button) {
    button.registerKeyboardAction(
            button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);

    button.registerKeyboardAction(
            button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Fires a button click when using the enter key
 * //from   w  ww  .  j a  v  a  2s. c om
 * @param button to press when enter is pressed
 */
public static void enterPressesWhenFocused(JButton button) {

    button.registerKeyboardAction(
            button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);

    button.registerKeyboardAction(
            button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);

}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/** 
 * Sets the focus default for the specified button.
 * /*from www.j  a v  a 2 s .c om*/
 * @param button The button to handle.
 */
public static void enterPressesWhenFocused(JButton button) {
    if (button == null)
        return;
    button.registerKeyboardAction(
            button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);

    button.registerKeyboardAction(
            button.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);
}