Java JButton enableEnter(JButton b)

Here you can find the source of enableEnter(JButton b)

Description

Enable activating button on Enter (which is replaced with spacebar for certain Look-And-Feels)

License

GNU General Public License

Declaration

public static void enableEnter(JButton b) 

Method Source Code

//package com.java2s;
// License: GPL. For details, see LICENSE file.

import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

public class Main {
    /**/*from   w  ww  . j  a  va2s.c  om*/
     * Enable activating button on Enter (which is replaced with spacebar for certain Look-And-Feels)
     */
    public static void enableEnter(JButton b) {
        b.setFocusable(true);
        b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
        b.getActionMap().put("enter", b.getAction());
    }
}

Related

  1. configureButton(JButton button)
  2. considerarSetaComoTab(JButton comp)
  3. copyButtonWidth(JButton toButton, JButton fromButton)
  4. doButtonClick(JButton button)
  5. drawCharacter(JPanel contentPane, ActionListener listener, String url, int x, int y, List buttons)
  6. ensureButtonWidth(JButton button, int width)
  7. enterPressesWhenFocused(final JButton button)
  8. equalizeButtons(JButton... buttons)
  9. exit(JButton aButton)