Example usage for javax.swing JFrame getY

List of usage examples for javax.swing JFrame getY

Introduction

In this page you can find the example usage for javax.swing JFrame getY.

Prototype

public int getY() 

Source Link

Document

Returns the current y coordinate of the components origin.

Usage

From source file:Main.java

/**
 * Used to centre the dialogs./*from w  w w  . j  a v  a  2  s  . c o m*/
 */
public static void centreOnParent(final JDialog dialog, final JFrame frame) {
    int x = frame.getX();
    x += (frame.getWidth() - dialog.getWidth()) / 2;

    int y = frame.getY();
    y += (frame.getHeight() - dialog.getHeight()) / 2;

    dialog.setLocation(x, y);
}

From source file:Main.java

public static void showFrame(JFrame frame, JFrame parent) {
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.pack();/*from w  ww .  j  a v a 2s.c  o  m*/
    frame.setLocation(parent.getX() + (parent.getWidth() - frame.getWidth()) / 2,
            parent.getY() + (parent.getHeight() - frame.getHeight()) / 2);
    frame.setVisible(true);
}

From source file:au.org.ala.delta.util.Utils.java

public static void centreWindow(Window c, JFrame frame) {
    Dimension app = frame.getSize();
    int x = frame.getX() + (app.width - c.getWidth()) / 2;
    int y = frame.getY() + (app.height - c.getHeight()) / 3;
    if (y < frame.getY()) {
        y = frame.getY();//  ww w.  j ava 2  s  . c om
    }
    c.setLocation(x, y);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @param frame to be positioned// w ww  .j av  a  2 s. c  o  m
 * 
 * positions frame on screen relative to position of TOPFRAME.
 * Sets frame.alwaysOnTop to true if TOPFRAME is maximized.
 */
public static void positionFrameRelativeToTopFrame(final JFrame frame) {
    // not sure of safest surest way to get main window???
    JFrame topFrame = (JFrame) UIRegistry.getTopWindow();

    // for now this just sets the top of frame to the top of topFrame
    // if there is room on the left side of topFrame, frame is set so it's right edge is next to topFrame's left edge.
    // otherwise, if frame will fit, frame's left edge is aligned with topFrame's right edge.
    // If it won't fit then frame's right edge is aligned with right of edge of screen.
    if (topFrame != null) {
        int x = 0;
        int y = topFrame.getY();
        Rectangle screenRect = topFrame.getGraphicsConfiguration().getBounds();
        if (topFrame.getX() >= frame.getWidth()) {
            x = topFrame.getX() - frame.getWidth();
        } else if (screenRect.width - topFrame.getX() - topFrame.getWidth() >= frame.getWidth()) {
            x = topFrame.getWidth();
        } else {
            x = screenRect.width - frame.getWidth();
        }
        frame.setBounds(x, y, frame.getWidth(), frame.getHeight());

        frame.setAlwaysOnTop(topFrame.getExtendedState() == Frame.MAXIMIZED_BOTH
                || topFrame.getExtendedState() == Frame.MAXIMIZED_VERT
                || topFrame.getExtendedState() == Frame.MAXIMIZED_HORIZ);
    }
}

From source file:org.objectstyle.cayenne.modeler.pref.ComponentGeometry.java

/**
 * Binds this preference object to synchronize its state with a given component,
 * allowing to specify an initial offset compared to the stored position.
 *///from   w  w w.  ja v  a  2 s. c om
public void bind(final JFrame frame, int initialWidth, int initialHeight, int maxOffset) {

    updateSize(frame, initialWidth, initialHeight);
    updateLocation(frame, maxOffset);

    frame.addComponentListener(new ComponentAdapter() {

        public void componentResized(ComponentEvent e) {
            setWidth(new Integer(frame.getWidth()));
            setHeight(new Integer(frame.getHeight()));
        }

        public void componentMoved(ComponentEvent e) {
            setX(new Integer(frame.getX()));
            setY(new Integer(frame.getY()));
        }
    });
}