Example usage for javax.swing JInternalFrame getDesktopPane

List of usage examples for javax.swing JInternalFrame getDesktopPane

Introduction

In this page you can find the example usage for javax.swing JInternalFrame getDesktopPane.

Prototype

@BeanProperty(bound = false)
public JDesktopPane getDesktopPane() 

Source Link

Document

Convenience method that searches the ancestor hierarchy for a JDesktop instance.

Usage

From source file:GUIUtils.java

/**
 * Centers passed internal frame within its desktop area. If centering would
 * cause the title bar to go off the top of the screen then move the window
 * down.//from w  ww . jav  a 2s .c  o  m
 * 
 * @param frame
 *          The internal frame to be centered.
 * 
 * @throws IllegalArgumentException
 *           If <TT>frame</TT> is <TT>null</TT>.
 */
public static void centerWithinDesktop(JInternalFrame frame) {
    if (frame == null) {
        throw new IllegalArgumentException("null JInternalFrame passed");
    }
    final Container parent = frame.getDesktopPane();
    if (parent != null && parent.isVisible()) {
        center(frame, new Rectangle(new Point(0, 0), parent.getSize()));
    }
}

From source file:SampleDesktop.java

public void dragFrame(JComponent f, int x, int y) {
    if (f instanceof JInternalFrame) { // Deal only w/internal frames
        JInternalFrame frame = (JInternalFrame) f;
        JDesktopPane desk = frame.getDesktopPane();
        Dimension d = desk.getSize();

        // Nothing all that fancy below, just figuring out how to adjust
        // to keep the frame on the desktop.
        if (x < 0) { // too far left?
            x = 0; // flush against the left side
        } else {//from  w ww . j a va 2  s.  co m
            if (x + frame.getWidth() > d.width) { // too far right?
                x = d.width - frame.getWidth(); // flush against right side
            }
        }
        if (y < 0) { // too high?
            y = 0; // flush against the top
        } else {
            if (y + frame.getHeight() > d.height) { // too low?
                y = d.height - frame.getHeight(); // flush against the
                // bottom
            }
        }
    }

    // Pass along the (possibly cropped) values to the normal drag handler.
    super.dragFrame(f, x, y);
}