Example usage for javax.swing JInternalFrame getHeight

List of usage examples for javax.swing JInternalFrame getHeight

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:Utils.java

/**
 * <p/>/*from   www  . j a  v  a 2  s .c  om*/
 * Returns the <code>Point</code> at which a window should be placed to
 * center that window on the given desktop.
 * </p>
 * <p/>
 * Some thought was taken as to whether to implement a method such as this,
 * or to simply make a method that, given a window, will center it.  It was
 * decided that it is better to not alter an object within a method.
 * </p>
 *
 * @param window  The window (JInternalFrame) to calculate the center point
 *                for.  This object can not be null.
 *
 * @return the <code>Point</code> at which the window should be placed to
 *         center that window on the given desktop
 */
public static Point getPointForCentering(JInternalFrame window) {
    try {
        //assert window != null;
        Point mousePoint = MouseInfo.getPointerInfo().getLocation();
        GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        for (GraphicsDevice device : devices) {
            Rectangle bounds = device.getDefaultConfiguration().getBounds();
            //check to see if the mouse cursor is within these bounds
            if (mousePoint.x >= bounds.x && mousePoint.y >= bounds.y
                    && mousePoint.x <= (bounds.x + bounds.width)
                    && mousePoint.y <= (bounds.y + bounds.height)) {
                //this is it
                int screenWidth = bounds.width;
                int screenHeight = bounds.height;
                int width = window.getWidth();
                int height = window.getHeight();
                return new Point(((screenWidth - width) / 2) + bounds.x,
                        ((screenHeight - height) / 2) + bounds.y);
            }
        }
    } catch (Exception e) {

    }
    return new Point(0, 0);
}

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 {/*w  ww  .j av  a  2  s  .  c  o 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);
}

From source file:InternalFrameTest.java

/**
 * Creates an internal frame on the desktop.
 * @param c the component to display in the internal frame
 * @param t the title of the internal frame.
 *//*  w  w w .  jav a 2s .  c  om*/
public void createInternalFrame(Component c, String t) {
    final JInternalFrame iframe = new JInternalFrame(t, true, // resizable
            true, // closable
            true, // maximizable
            true); // iconifiable

    iframe.add(c, BorderLayout.CENTER);
    desktop.add(iframe);

    iframe.setFrameIcon(new ImageIcon("document.gif"));

    // add listener to confirm frame closing
    iframe.addVetoableChangeListener(new VetoableChangeListener() {
        public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
            String name = event.getPropertyName();
            Object value = event.getNewValue();

            // we only want to check attempts to close a frame
            if (name.equals("closed") && value.equals(true)) {
                // ask user if it is ok to close
                int result = JOptionPane.showInternalConfirmDialog(iframe, "OK to close?", "Select an Option",
                        JOptionPane.YES_NO_OPTION);

                // if the user doesn't agree, veto the close
                if (result != JOptionPane.YES_OPTION)
                    throw new PropertyVetoException("User canceled close", event);
            }
        }
    });

    // position frame
    int width = desktop.getWidth() / 2;
    int height = desktop.getHeight() / 2;
    iframe.reshape(nextFrameX, nextFrameY, width, height);

    iframe.show();

    // select the frame--might be vetoed
    try {
        iframe.setSelected(true);
    } catch (PropertyVetoException e) {
    }

    frameDistance = iframe.getHeight() - iframe.getContentPane().getHeight();

    // compute placement for next frame

    nextFrameX += frameDistance;
    nextFrameY += frameDistance;
    if (nextFrameX + width > desktop.getWidth())
        nextFrameX = 0;
    if (nextFrameY + height > desktop.getHeight())
        nextFrameY = 0;
}