Java Code Examples for javax.swing.JOptionPane#getRootFrame()

The following examples show how to use javax.swing.JOptionPane#getRootFrame() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowUtils.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @param comp The {@link Component} to use. May be {@code null}.
 * @return The most logical {@link Window} associated with the component.
 */
public static Window getWindowForComponent(Component comp) {
    while (true) {
        if (comp == null) {
            return JOptionPane.getRootFrame();
        }
        if (comp instanceof Frame || comp instanceof Dialog) {
            return (Window) comp;
        }
        comp = comp.getParent();
    }
}
 
Example 2
Source File: JFontChooser.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows a modal font-chooser dialog and blocks until the dialog is
 * hidden. If the user presses the "OK" button, then this method
 * hides/disposes the dialog and returns the selected color. If the
 * user presses the "Cancel" button or closes the dialog without
 * pressing "OK", then this method hides/disposes the dialog and
 * returns <code>null</code>.
 * 
 * @param parent the parent <code>Component</code> for the
 *          dialog
 * @param title the String containing the dialog's title
 * @param initialFont the initial Font set when the font-chooser is
 *          shown
 * @return the selected font or <code>null</code> if the user
 *         opted out
 * @exception java.awt.HeadlessException if GraphicsEnvironment.isHeadless()
 *              returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public static Font showDialog(Component parent, String title, Font initialFont) {
  BaseDialog dialog;
  Window window = (parent == null?JOptionPane.getRootFrame():SwingUtilities
    .windowForComponent(parent));
  if (window instanceof Frame) {
    dialog = new BaseDialog((Frame)window, title, true);
  } else {
    dialog = new BaseDialog((Dialog)window, title, true);
  }
  dialog.setDialogMode(BaseDialog.OK_CANCEL_DIALOG);
  dialog.getBanner().setVisible(false);

  JFontChooser chooser = new JFontChooser();
  chooser.setSelectedFont(initialFont);

  dialog.getContentPane().setLayout(new BorderLayout());
  dialog.getContentPane().add("Center", chooser);
  dialog.pack();
  dialog.setLocationRelativeTo(parent);

  if (dialog.ask()) {
    return chooser.getSelectedFont();
  } else {
    return null;
  }
}
 
Example 3
Source File: ExtendedJFileChooser.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Window getWindowForComponent(Component parentComponent) throws HeadlessException {
	if (parentComponent == null) {
		return JOptionPane.getRootFrame();
	}
	if (parentComponent instanceof Frame || parentComponent instanceof Dialog) {
		return (Window) parentComponent;
	}
	return getWindowForComponent(parentComponent.getParent());
}
 
Example 4
Source File: Launch.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
protected static void showAboutFrame()
{
	final JDialog jd = new JDialog(JOptionPane.getRootFrame(), "About DroidUIBuilder");
	jd.getContentPane().setLayout(new BorderLayout());
	jd.getContentPane().add(new JLabel(new ImageIcon(ImageResources.instance().getImage(
					"droiddraw_small"))), BorderLayout.CENTER);
	jd.pack();
	jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	jd.setResizable(false);
	jd.setLocationRelativeTo(null);
	jd.setVisible(true);
}
 
Example 5
Source File: Launch.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
protected static void showSurportFrame()
{
	DonatePanel dp = new DonatePanel();
	dp.setBorder(BorderFactory.createEmptyBorder(100,100,100,300));
	final JDialog jd = new JDialog(JOptionPane.getRootFrame(), "Support us");
	jd.getContentPane().setLayout(new BorderLayout());
	jd.getContentPane().add(dp, BorderLayout.CENTER);
	jd.pack();
	jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	jd.setResizable(false);
	jd.setLocationRelativeTo(null);
	jd.setVisible(true);
}