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().getActionMap().put("FindNext", new FindExploreAction(true)); this.getRootPane().getActionMap().put("FindPrevious", new FindExploreAction(false));
mainWindow.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sfuncF4, "CloseTab"); mainWindow.getRootPane().getActionMap().put("CloseTab", new AbstractAction() { private static final long serialVersionUID = -885398399200419492L;
/** * 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); }
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().getActionMap().put(actionKey, cancelAction); addWindowListener( new WindowAdapter() {
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) {
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) {
// 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);
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(); } }); }
/** * Removes the action for this button. Since a new button will be created * everytime they are updated, the action will not be readded for this * button, so the shortcut will have no action to perform. It's easier to * remove from the action map based on the button than from the input map. * * @param button */ private void clearShortcut(JButton button) { owner.getRootPane().getActionMap().remove(button); }
/** * 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()); }