Example usage for java.awt Window getParent

List of usage examples for java.awt Window getParent

Introduction

In this page you can find the example usage for java.awt Window getParent.

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:Main.java

/**
 * Center a window on screen.//from w  w w  . j a  v  a  2  s . c om
 *
 * @param w
 *          the window to center on screen.
 */
public static void centerInParent(Window w) {
    Container parent = w.getParent();
    if (parent != null) {
        Dimension parentSize = parent.getSize();
        w.setLocation(parent.getX() + (parentSize.width - w.getWidth()) / 2,
                parent.getY() + (parentSize.height - w.getHeight()) / 2);
    }
}

From source file:GUIUtils.java

/**
 * Centers <CODE>wind</CODE> within its parent. If it has no parent then
 * center within the screen. If centering would cause the title bar to go
 * above the parent (I.E. cannot see the titlebar and so cannot move the
 * window) then move the window down.//  w  w  w  . j  ava 2s.c o  m
 * 
 * @param wind
 *          The Window to be centered.
 * 
 * @throws IllegalArgumentException
 *           If <TT>wind</TT> is <TT>null</TT>.
 */
public static void centerWithinParent(Window wind) {
    if (wind == null) {
        throw new IllegalArgumentException("null Window passed");
    }
    final Container parent = wind.getParent();
    if (parent != null && parent.isVisible()) {
        center(wind, new Rectangle(parent.getLocationOnScreen(), parent.getSize()));
    } else {
        centerWithinScreen(wind);
    }
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * Adds the complete hierarchy of the given <code>window</code> to the
 * hierarchy. <br>//from  w  w  w .  ja  v a2s  .com
 * @param window a new (and opened) window
 */
public void add(Window window) {
    // if window has no parent, its a new top level container, otherwise
    // the parent is already in the AutHierarchy, 
    // NO!: creating a Window without a parent, calling show()
    // -> window.getParent() == SwingUtilities$1
    // don't add, if in hierarchy map yet

    if (getRealMap().get(window) == null || getHierarchyContainer(window) == null) {

        if (log.isInfoEnabled()) {
            log.info("adding window " + window); //$NON-NLS-1$            
        }

        // create a new SwingHierarchyContainer for window 
        SwingComponent componentID = new SwingComponent(window);
        SwingHierarchyContainer hierarchyWindow = new SwingHierarchyContainer(componentID);
        // update the hash table
        addToHierachyMap(hierarchyWindow);
        // add a window listener for window closed events
        registerAsWindowListener(window);
        // get the parent of window, if any
        Container parent = window.getParent();
        if (parent != null) {
            SwingHierarchyContainer hierarchyParent = getHierarchyContainer(parent);
            if (hierarchyParent == null) {
                // a new container, see comment at top of the method
                hierarchyParent = new SwingHierarchyContainer(new SwingComponent(parent));
            }
            name(hierarchyParent);
            // add the new container for the window to hierarchyParent
            hierarchyParent.add(hierarchyWindow);
            hierarchyWindow.setParent(hierarchyParent);
            name(hierarchyWindow);
            // update m_hierarchyMap
            addToHierachyMap(hierarchyParent);
            addToHierarchyUp(hierarchyParent, parent);
        }
    }
    // registering this class as a container listener happens in
    // addToHierarchy
    addToHierarchyDown(getHierarchyContainer(window), window);
}