Java Utililty Methods JFrame Parent

List of utility methods to do JFrame Parent

Description

The list of methods to do JFrame Parent are organized into topic(s).

Method

JFramerootFrame(@Nonnull Component component)
root Frame
Window window = SwingUtilities.getWindowAncestor(component);
if (window instanceof JFrame) {
    return (JFrame) window;
return null;
voidrunProgressDialog(Runnable runnable, Frame parentFrame, String title, int count)
Run progress dialog.
JProgressBar progressBar = createJProgressBar(count);
JDialog dialog = createProgressDialog(parentFrame, title, progressBar);
runProgressBar(runnable, dialog);
voidsetFrameParentTitle(Container c, String s)
set Frame Parent Title
Container parent = getFrameParent(c);
if (parent instanceof JInternalFrame)
    ((JInternalFrame) parent).setTitle(s);
else if (parent instanceof Frame)
    ((Frame) parent).setTitle(s);
voidshowDialog(Frame aParent, String aMsg, String aTitle, int aType)
Displays a message dialog
aParent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
JOptionPane.showMessageDialog(aParent, aMsg, aTitle, aType);
booleanshowDialog(Frame parent, String title, JComponent c)
Show the dialog with OK, Cancel buttons.
return (showDialog(parent, title, c, true));
voidshowDoneDialog(Frame parent, String title, JComponent c)
A simple dialog that allows one to show a user a given component.
final JButton done = new JButton("Done");
final JDialog dialog = new JDialog(parent, title, true);
done.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
        dialog.setVisible(false);
        done.setText("true");
        dialog.dispose();
});
dialog.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 1;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
dialog.getContentPane().add(c, gbc);
gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.gridwidth = 1;
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
dialog.getContentPane().add(new JSeparator(), gbc);
gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.gridwidth = 1;
gbc.gridx = 0;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(4, 4, 4, 4);
dialog.getContentPane().add(done, gbc);
dialog.pack();
dialog.setLocationRelativeTo(parent);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
voidshowGeneralErrorDialog(Frame parent, String title, String message)
Shows an error message dialog.
JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
voidshowInfoDialog(final Frame parent, final String msg)
Shows a dialog with a message.
JOptionPane.showMessageDialog(parent, msg);
voidshowNothingIsSelectedForRemoveDialog(Frame parent)
Shows the 'update was successful' dialog.
JOptionPane.showMessageDialog(parent, "Nothing is selected to remove.", "Nothing selected to remove.",
        JOptionPane.INFORMATION_MESSAGE);
voidshowSignatureUpdateErrorDialog(Frame parent, Throwable e)
Shows an error message dialog.
JOptionPane.showMessageDialog(parent, e.getLocalizedMessage(), SIGNATURE_UPDATE, JOptionPane.ERROR_MESSAGE);