private void setHideOnEscapeButton() { Action escapeAction = new AbstractAction() { private static final long serialVersionUID = 5572504000935312338L; @Override public void actionPerformed(ActionEvent e) { FindBox.this.setVisible(false); } }; KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE"); this.getRootPane().getActionMap().put("ESCAPE", escapeAction); }
private void setHideOnEscapeButton() { Action escapeAction = new AbstractAction() { private static final long serialVersionUID = 6846566740472934801L; @Override public void actionPerformed(ActionEvent e) { FindAllBox.this.setVisible(false); } }; KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE"); this.getRootPane().getActionMap().put("ESCAPE", escapeAction); }
private static final KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); public static final String dispatchWindowClosingActionMapKey = "com.spodding.tackline.dispatch:WINDOW_CLOSING"; public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent( dialog, WindowEvent.WINDOW_CLOSING )); } }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( escapeStroke, dispatchWindowClosingActionMapKey ); root.getActionMap().put( dispatchWindowClosingActionMapKey, dispatchClosing ); }
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(funcF3, "FindNext"); this.getRootPane().getActionMap().put("FindNext", new FindExploreAction(true)); this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sfuncF3, "FindPrevious"); this.getRootPane().getActionMap().put("FindPrevious", new FindExploreAction(false));
mainWindow.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sfuncF4, "CloseTab");
/** * Adds key bindings to this popup. */ private void installKeyBindings() { InputMap im = getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getRootPane().getActionMap(); KeyStroke escapeKS = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); im.put(escapeKS, "onEscape"); am.put("onEscape", new EscapeAction()); }
public void run() { JFrame frame = new JFrame(pTitle); frame.getRootPane().getActionMap().put("window-close", new AbstractAction() { public void actionPerformed(ActionEvent e) { Window window = SwingUtilities.getWindowAncestor((Component) e.getSource()); window.setVisible(false); window.dispose(); } }); frame.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "window-close"); frame.addWindowListener(new ExitIfNoWindowPresentHandler()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationByPlatform(true); JPanel pane = new JPanel(new BorderLayout()); JScrollPane scroll = new JScrollPane(pImage != null ? new ImageLabel(pImage) : new JLabel("(no image data)", JLabel.CENTER)); scroll.setBorder(null); pane.add(scroll); frame.setContentPane(pane); frame.pack(); frame.setVisible(true); } });
/** * Adds key bindings to this popup. */ private void installKeyBindings() { InputMap im = getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getRootPane().getActionMap(); KeyStroke escapeKS = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); im.put(escapeKS, "onEscape"); am.put("onEscape", new EscapeAction()); list.getInputMap().remove(escapeKS); }
rootPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, forwardKeys2); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = rootPane.getActionMap();
/** * Creates new form DownloadImagesDialog */ public DownloadImagesDialog() { initComponents(); this.setModal(true); // fix for panelInfo (it's resets aligmentX after netbeans designer opened) panelInfo.setAlignmentX(CENTER_ALIGNMENT); // save default sizes // this.sizeModeMessageAndControls = new Dimension(580, 330); // dialog -> properties -> designer size // this.sizeModeMessageOnly = new Dimension(this.sizeModeMessageAndControls.getSize()); sizeModeMessageOnly.height = 25 * 4; sizeModeMessageOnly.width = sizeModeMessageOnly.width / 2; // Close the dialog when Esc is pressed String cancelName = "cancel"; InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = getRootPane().getActionMap(); actionMap.put(cancelName, new AbstractAction() { public void actionPerformed(ActionEvent e) { doClose(RET_CANCEL); } }); }
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(k, actionKey);
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = getRootPane().getActionMap();
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = getRootPane().getActionMap();
// Action action = ... // KeyStroke stroke = ... JRootPane rootPane = mainJFrame.getRootPane(); rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "myAction"); rootPane.getActionMap().put("myAction", action);
// We add binding to the RootPane JRootPane rootPane = frame.getRootPane(); //Specify the KeyStroke and give the action a name KeyStroke KEY = KeyStroke.getKeyStroke("control S"); String actionName = "captureMouseLoc"; //map the keystroke to the actionName rootPane.getInputMap().put(KEY, actionName); //map the actionName to the action itself rootPane.getActionMap().put(actionName, action);
/** * Adds a single regular hotkey to the given JRootPane. * * @param hotkey * @param pane */ private void addHotkey(Hotkey hotkey, JRootPane pane) { String id = String.valueOf(hotkey.hashCode()); pane.getInputMap(INPUT_MAP_KEY).put(hotkey.keyStroke, PREFIX + id); pane.getActionMap().put(PREFIX + id, createAction(hotkey)); }
void $afterCompleteSetup() { JRootPane rootPane = ui.getRootPane(); JButton close = ui.close; rootPane.setDefaultButton(close); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "close"); rootPane.getActionMap().put("close", close.getAction()); } }
public static void escapeCancels(final JDialog dialog) { dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE"); dialog.getRootPane().getActionMap().put("ESCAPE", new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { dialog.dispose(); } }); }
/** * Adds key bindings to this popup. */ private void installKeyBindings() { InputMap im = getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getRootPane().getActionMap(); KeyStroke escapeKS = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); im.put(escapeKS, "onEscape"); am.put("onEscape", new EscapeAction()); }
public ResultingDialog(Window parentWindow, String aTitle, ModalityType mType) { super(parentWindow, aTitle, mType); ActionMap am = getRootPane().getActionMap(); EscapeAction escapeAction = new EscapeAction(); am.put(EscapeAction.class.getSimpleName(), escapeAction); InputMap im = getRootPane().getInputMap(); im.put((KeyStroke) escapeAction.getValue(Action.ACCELERATOR_KEY),EscapeAction.class.getSimpleName()); }