List of utility methods to do Swing Key Action
String | getPrettyStringFor(KeyStroke keyStroke) Returns a pretty string value for a KeyStroke, suitable for display as the keystroke's value in a GUI. if (keyStroke == null) return ""; String string = KeyEvent.getKeyModifiersText(keyStroke.getModifiers()); if (string != null && string.length() > 0) string += "+"; int keyCode = keyStroke.getKeyCode(); if (keyCode != KeyEvent.VK_SHIFT && keyCode != KeyEvent.VK_CONTROL && keyCode != KeyEvent.VK_ALT && keyCode != KeyEvent.VK_META) ... |
KeyStroke | getSystemHelpKey() get key that initiates help system return KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
|
JPanel | getTypePanel(final ActionListener typeListener) get Type Panel final JRadioButton fourPlexButton = new JRadioButton("4-plex"); fourPlexButton.setMnemonic(KeyEvent.VK_4); fourPlexButton.setSelected(true); fourPlexButton.setActionCommand("4"); final JRadioButton eightPlexButton = new JRadioButton("8-plex"); eightPlexButton.setMnemonic(KeyEvent.VK_8); eightPlexButton.setActionCommand("8"); final ButtonGroup typeGroup = new ButtonGroup(); ... |
void | handleSliderAdjustmentViaKey(KeyEvent e) Checks if a slider has been adjusted by a keystroke. if (e.getSource() instanceof JSlider) { if (KeyEvent.VK_LEFT == e.getKeyCode() || KeyEvent.VK_RIGHT == e.getKeyCode() || KeyEvent.VK_UP == e.getKeyCode() || KeyEvent.VK_DOWN == e.getKeyCode() || KeyEvent.VK_PAGE_UP == e.getKeyCode() || KeyEvent.VK_PAGE_DOWN == e.getKeyCode() || KeyEvent.VK_HOME == e.getKeyCode() || KeyEvent.VK_END == e.getKeyCode()) { JSlider slider = (JSlider) e.getSource(); for (ChangeListener listener : slider.getChangeListeners()) { slider.setValueIsAdjusting(true); ... |
JButton | initButton(String text, String actionKey, int shortcutKey, int modifiers, JComponent component, AbstractAction action) init Button setKeyBinding(actionKey, shortcutKey, modifiers, action, component); JButton button = new JButton(action); button.setText(text); button.setMnemonic(shortcutKey); return button; |
void | installCloseKey(final RootPaneContainer c) Install a key listener on a window to close it. ActionListener closer = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { ((Component) c).setVisible(false); }; JRootPane rootPane = c.getRootPane(); Toolkit toolkit = ((Component) c).getToolkit(); ... |
boolean | invoke(Action action, Object source) invoke if (action == null || !action.isEnabled()) { return false; ActionEvent evt = new ActionEvent(source, ActionEvent.ACTION_PERFORMED, (String) action.getValue(Action.ACTION_COMMAND_KEY), 0); action.actionPerformed(evt); return true; |
boolean | isActionSelected(Action action) is Action Selected if (action == null) return false; Boolean result = (Boolean) action.getValue(Action.SELECTED_KEY); return result == null ? false : result; |
boolean | isKeyStrokeEvent(@Nullable final KeyStroke keyStroke, final int keyEventType, @Nullable final KeyEvent event) is Key Stroke Event boolean result = false; if (keyStroke != null && event != null) { if (keyEventType == keyStroke.getKeyEventType()) { result = ((keyStroke.getModifiers() & event.getModifiers()) == keyStroke.getModifiers()) && (keyStroke.getKeyCode() == event.getKeyCode()); return result; ... |
boolean | isValidKey(int keyCode) Returns whether the specified key code is valid. switch (keyCode) { case KeyEvent.VK_ENTER: case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_TAB: case KeyEvent.VK_CANCEL: case KeyEvent.VK_CLEAR: case KeyEvent.VK_SHIFT: case KeyEvent.VK_CONTROL: ... |