List of usage examples for javax.swing JFrame getExtendedState
public int getExtendedState()
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param frame to be positioned//from ww w . j a va 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); } }