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

voidensureVisibilityAtParent(final JInternalFrame frame)
ensure Visibility At Parent
final JComponent parent = (JComponent) frame.getParent();
final Rectangle parentRect = SwingUtilities.calculateInnerArea(parent, null);
final Rectangle frameRect = frame.getBounds();
final int x = Math.min(frameRect.x, Math.max(0, parentRect.width - frameRect.width));
final int y = Math.min(frameRect.y, Math.max(0, parentRect.height - frameRect.height));
frame.setLocation(x, y);
voidexecLoop(JComponent editor, Frame parent, boolean modal, int w, int h)
exec Loop
JDialog dialog = new JDialog(parent, modal);
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BorderLayout());
JScrollPane scrollPane = new JScrollPane(editor);
contentPane.add(scrollPane, BorderLayout.CENTER);
dialog.setSize(w, h);
centerWindow(dialog);
dialog.setVisible(true);
...
FilefileOpen(Frame parent, String typename, String ext)
file Open
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(typename, ext);
chooser.setFileFilter(filter);
chooser.setCurrentDirectory(lastpathload != null ? new File(lastpathload) : null);
int returnVal = chooser.showOpenDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    lastpathload = chooser.getSelectedFile().getPath();
    return chooser.getSelectedFile();
...
ObjectfindParentDialogOrFrame(Container container)
Look for a JDialog or JFrame in the parent hierarchy of this specified container and return that JDialog or JFrame.
while (container != null) {
    if (container instanceof JFrame || container instanceof JDialog) {
        return container;
    container = container.getParent();
return null;
ComponentgetFirstParentFrameOrDialog(Component cmp)
Return the first parent that is a JFrame or a JDialog.
while (cmp != null) {
    if (cmp instanceof JFrame || cmp instanceof JDialog) {
        return cmp;
    cmp = cmp.getParent();
return null;
FramegetFrame(Component parent)
Find the parent Frame.
if (parent == null) {
    Frame option = JOptionPane.getRootFrame();
    if (!option.getClass().getName().startsWith("javax.swing.SwingUtilities$")) {
        return option;
    Frame best = null;
    int bestSize = 0;
    Frame[] frames = Frame.getFrames();
...
JFramegetFrameParent(Component component)
get Frame Parent
Window windowAncestor = getWindowParent(component);
if (windowAncestor instanceof JFrame)
    return (JFrame) windowAncestor;
return null;
ActiongetInstalledOperation(final RootPaneContainer frame, final Object actionKey, boolean selfOnly)
Returns the Action installed under the specified action key in the specified frame.
JRootPane root = frame.getRootPane();
if (selfOnly) {
    ActionMap actionMap = root.getActionMap();
    ActionMap parentMap = actionMap.getParent();
    actionMap.setParent(null);
    Action result = actionMap.get(actionKey);
    actionMap.setParent(parentMap);
    return result;
...
FramegetParentalFrame(Component n)
Get the Frame a Component is contained in.
while (!(n instanceof Frame) && n != null)
    n = n.getParent();
return (Frame) n;
JFramegetParentFrame(Component component)
get Parent Frame
Component frame = component;
while (!(frame instanceof JFrame)) {
    frame = frame.getParent();
    if (frame == null) {
        break;
return (JFrame) frame;
...