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

FramegetRootFrame()
get Root Frame
if (frame == null) {
    frame = new Frame();
    frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    positionCenterScreen(frame);
return frame;
JFramegetRootFrame(Component aComp)
get Root Frame
Component lParent = aComp;
while (lParent != null && !(lParent instanceof JFrame)) {
    lParent = lParent.getParent();
if (lParent != null && lParent instanceof JFrame) {
    return (JFrame) lParent;
return null;
...
FramegetRootFrame(Component c)
Get the root frame of any component
if (c != null) {
    Window window = SwingUtilities.getWindowAncestor(c);
    if (window instanceof Frame) {
        return (Frame) window;
    } else if (window instanceof Dialog) {
        Dialog dialog = (Dialog) window;
        return getRootFrame(dialog.getOwner());
return getPhonyFrame();
java.awt.FramegetRootFrame(java.awt.Component c)
get Root Frame
java.awt.Component root = javax.swing.SwingUtilities.getRoot(c);
if (root instanceof java.awt.Frame) {
    return (java.awt.Frame) root;
} else {
    return null;
FramegetRootFrame(JComponent component)
get Root Frame
Component c = component;
while (!(c instanceof Frame))
    c = c.getParent();
return ((Frame) c);
voidgetSpssInstallationDirectory(Frame parent)
get Spss Installation Directory
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Set IBM SPSS directory");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.showOpenDialog(null);
System.out.println(fileChooser.getSelectedFile().getPath());
voidinstallOperation(final RootPaneContainer frame, final int condition, final KeyStroke keyStroke, final String actionKey, Action action)
Installs a keybind in the specified frame for the specified action.
JRootPane root = frame.getRootPane();
root.getInputMap(condition).put(keyStroke, actionKey);
root.getActionMap().put(actionKey, action);
BooleanisFrameModified(RootPaneContainer frame)
is Frame Modified
synchronized (frame) {
    JRootPane rootPane = frame.getRootPane();
    Object obj = rootPane.getClientProperty(WINDOW_MODIFIED);
    if (obj == null || !(obj instanceof Boolean)) {
        return Boolean.FALSE;
    return (Boolean) obj;
booleanokToWriteFile(Frame parent, String fileName)
ok To Write File
File f = new File(fileName);
if (f.isDirectory()) {
    JOptionPane.showMessageDialog(parent, fileName + " is a directory.", "Error!",
            JOptionPane.ERROR_MESSAGE);
    return false;
} else if (f.exists()) {
    int saveAnswer = JOptionPane.showConfirmDialog(parent,
            "File " + fileName + " already exists.\nDo you want to overwrite?", "Question",
...
voidoops(Frame parent, String s)
Oops message.
JOptionPane.showMessageDialog(parent, s, "Oops", JOptionPane.INFORMATION_MESSAGE);