Example usage for javax.swing JButton registerKeyboardAction

List of usage examples for javax.swing JButton registerKeyboardAction

Introduction

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

Prototype

public void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition) 

Source Link

Document

This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similar behavior.

Usage

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

/**
 * Registers the enter key a {@link JButton}.
 * //from  www .  j av  a  2s  .co  m
 * @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
 * //www  . j av  a 2  s  . c  o  m
 * @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.
 * //ww  w  .java  2  s  .c  o m
 * @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);
}