List of usage examples for javax.swing JDialog getRootPane
@BeanProperty(bound = false, hidden = true, description = "the RootPane object for this dialog.") public JRootPane getRootPane()
From source file:org.ut.biolab.medsavant.client.util.ClientMiscUtils.java
/** * Register the escape key so that it can be used to cancel the associated JDialog. */// w w w . j a va 2 s.c om public static void registerCancelButton(final JButton cancelButton) { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); JDialog dialog = (JDialog) SwingUtilities.getWindowAncestor(cancelButton); dialog.getRootPane().registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { cancelButton.doClick(); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); }
From source file:pcgen.gui2.PCGenFrame.java
private void showLicenseDialog(String title, String htmlString) { if (htmlString == null) { htmlString = LanguageBundle.getString("in_licNoInfo"); //$NON-NLS-1$ }//from w w w . j a va 2s. c o m final PropertyContext context = PCGenSettings.OPTIONS_CONTEXT; final JDialog aFrame = new JDialog(this, title, true); final JButton jClose = new JButton(LanguageBundle.getString("in_close")); //$NON-NLS-1$ jClose.setMnemonic(LanguageBundle.getMnemonic("in_mn_close")); //$NON-NLS-1$ final JPanel jPanel = new JPanel(); final JCheckBox jCheckBox = new JCheckBox(LanguageBundle.getString("in_licShowOnLoad")); //$NON-NLS-1$ jPanel.add(jCheckBox); jCheckBox.setSelected(context.getBoolean(PCGenSettings.OPTION_SHOW_LICENSE)); jCheckBox.addItemListener( evt -> context.setBoolean(PCGenSettings.OPTION_SHOW_LICENSE, jCheckBox.isSelected())); jPanel.add(jClose); jClose.addActionListener(evt -> aFrame.dispose()); HtmlPanel htmlPanel = new HtmlPanel(); HtmlRendererContext theRendererContext = new SimpleHtmlRendererContext(htmlPanel, new SimpleUserAgentContext()); htmlPanel.setHtml(htmlString, "", theRendererContext); aFrame.getContentPane().setLayout(new BorderLayout()); aFrame.getContentPane().add(htmlPanel, BorderLayout.CENTER); aFrame.getContentPane().add(jPanel, BorderLayout.SOUTH); aFrame.setSize(new Dimension(700, 500)); aFrame.setLocationRelativeTo(this); Utility.setComponentRelativeLocation(this, aFrame); aFrame.getRootPane().setDefaultButton(jClose); Utility.installEscapeCloseOperation(aFrame); aFrame.setVisible(true); }
From source file:pcgen.gui2.tools.Utility.java
/** * Add a keyboard shortcut to allow ESC to close the dialog. * * @param dialog The dialog to be updated. *//*from w ww . jav a 2 s.c om*/ public static void installEscapeCloseOperation(final JDialog dialog) { JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey); Action dispatchClosing = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); } }; root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing); }