public static void addEscapeListener(final JDialog dialog) { ActionListener escListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }; dialog.getRootPane().registerKeyboardAction(escListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); }
alternateEncodingPrompt(encoding); }); dialog.getRootPane().setDefaultButton(useNewEncoding); dialog.pack(); dialog.setLocationRelativeTo(this);
}); cancel.addActionListener(e -> dialog.setVisible(false)); dialog.getRootPane().setDefaultButton(okay); dialog.pack(); dialog.setLocationRelativeTo(this);
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 ); }
public int show(JFrame frame) { dialog = new JDialog(frame, "Save Changes", true); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(this, BorderLayout.CENTER); dialog.setResizable(false); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.getRootPane().setDefaultButton(saveButton); dialog.setVisible(true); dialog.dispose(); return selectedValue; }
pack(); getRootPane().setDefaultButton( ok );
/** * {@inheritDoc} */ @Override public JXRootPane getRootPane() { return (JXRootPane) super.getRootPane(); }
/** * {@inheritDoc} */ @Override public JXRootPane getRootPane() { return (JXRootPane) super.getRootPane(); }
/** * {@inheritDoc} */ @Override public JXRootPane getRootPane() { return (JXRootPane) super.getRootPane(); }
/** * Register a popout window, so regular hotkeys can be added to it if * necessary. References are saved in a WeakHashMap. * * @param popout */ public void registerPopout(JDialog popout) { popouts.put(popout, null); addHotkeys(popout.getRootPane()); }
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(); } }); }
/** returns the root pane used by this detached dockable container, regardless of its type (frame or dialog)*/ public static JRootPane getRootPane(FloatingDockableContainer fdc) { if(fdc instanceof JFrame) { return ((JFrame) fdc).getRootPane(); } else if(fdc instanceof JDialog) { return ((JDialog) fdc).getRootPane(); } else { return null; // not reachable } }
public static void addKeyActionToDialog(final JDialog dialog, final Action action, final String keyStroke, final String actionId) { action.putValue(Action.NAME, actionId); dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(keyStroke), action.getValue(Action.NAME)); dialog.getRootPane().getActionMap().put(action.getValue(Action.NAME), action); }
@Override public void setWaitingCursor(final boolean waiting) { if (waiting) { dialog.getRootPane().getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); dialog.getRootPane().getGlassPane().setVisible(true); } else { dialog.getRootPane().getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); dialog.getRootPane().getGlassPane().setVisible(false); } }
private void setupKeyboardActions() { JRootPane rootPane = dialog.getRootPane(); rootPane.setDefaultButton(getApproveButton()); rootPane.registerKeyboardAction(cancelAction, getKeyStroke(VK_ESCAPE, 0), WHEN_IN_FOCUSED_WINDOW); }
private void paintImmediately() { if (dialog instanceof JDialog) { JDialog jdialog = (JDialog) dialog; JComponent rootPane = jdialog.getRootPane(); final Rectangle rect = new Rectangle(); rootPane.getBounds(rect); rect.x = 0; rect.y = 0; rootPane.paintImmediately(rect); } }
/** * Set cursor to busy and disable application input. This can be reversed by * a subsequent call to setCursorFree. * * @param dialog * Dialog to apply to */ public static void setCursorBusy(JDialog dialog) { setCursorBusy(dialog.getRootPane().getGlassPane()); }
/** * Set cursor to free and enable application input. Called after a call to * setCursorBusy. * * @param dialog * Dialog to apply to */ public static void setCursorFree(JDialog dialog) { setCursorFree(dialog.getRootPane().getGlassPane()); }
/** * Removes all hotkeys that have to be registered (regular and global). */ private void removeAllHotkeys() { removeHotkeys(main.getRootPane()); for (JDialog popout : popouts.keySet()) { removeHotkeys(popout.getRootPane()); } removeGlobalHotkeys(); removeHotkeysFromActions(); }
void stopComputing() { if (stop_ != null) { stop_.setVisible(false); if (owner_ != null) { owner_.getRootPane().remove(stop_); } } owner_.setCursor(Cursor.getDefaultCursor()); }