List of usage examples for javax.swing JRootPane getInputMap
public final InputMap getInputMap(int condition)
InputMap
that is used during condition
. From source file:Main.java
public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }//from w ww . j a v a2 s. c om }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY); root.getActionMap().put(ESCAPE_KEY, dispatchClosing); }
From source file:Main.java
public static void installEscapeCloseOperation(final JFrame dialog) { Action dispatchClosing = new AbstractAction() { public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }/*ww w .j av a 2 s . com*/ }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY); root.getActionMap().put(ESCAPE_KEY, dispatchClosing); }
From source file:Main.java
public static void closeOnEscape(final JFrame frame) { KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false);/*from w w w. j av a2 s . c o m*/ frame.dispose(); } }; JRootPane rootPane = frame.getRootPane(); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); }
From source file:Main.java
public static void setCancelButton(final JRootPane rp, final JButton b) { rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); rp.getActionMap().put("cancel", new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent ev) { b.doClick();//from w w w . j ava 2s .c om } }); }
From source file:Main.java
public static void setDontSaveButton(final JRootPane rp, final JButton b) { rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0), "dontSave"); rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_D, rp.getToolkit().getMenuShortcutKeyMask()), "dontSave"); rp.getActionMap().put("dontSave", new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent ev) { b.doClick();/* w w w . ja v a 2 s . c om*/ } }); }
From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java
public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); }/* w w w . j av a2 s . c om*/ }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing); }
From source file:net.sf.jabref.util.Util.java
/** * Binds ESC-Key to cancel button//from w w w. j a v a2s .c o m * * @param rootPane the pane to bind the action to. Typically, this variable is retrieved by this.getRootPane(); * @param cancelAction the action to bind */ // TODO: move to GUI public static void bindCloseDialogKeyToCancelAction(JRootPane rootPane, Action cancelAction) { InputMap im = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap am = rootPane.getActionMap(); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); }
From source file:FrameKey.java
protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { setVisible(false);/*w w w . ja v a 2 s . c o m*/ } }; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); return rootPane; }
From source file:EscapeDialog.java
License:asdf
protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("about to disappear"); setVisible(false);/*from w ww . ja va 2 s . c o m*/ } }; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); return rootPane; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Creates Action objects and initializes Input and Action mappings *//*from w ww .j ava 2 s. c o m*/ private void initActions() { JRootPane rp = getRootPane(); ActionMap am = rp.getActionMap(); InputMap im = rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); am.put(DeleteAction.class, deleteAction); am.put(CloneAction.class, cloneAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DeleteAction.class); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), CloneAction.class); }