public void setVisible(boolean visible) { if (visible) { int x = (int) getOwner().getLocation().getX() + (getOwner().getWidth() / 2) - (getWidth() / 2); int y = (int) getOwner().getLocation().getY() + (getOwner().getHeight() / 2) - (getHeight() / 2); setLocation(adjustX(x), adjustY(y)); } super.setVisible(visible); }
final Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), rootPane); final Window window = SwingUtilities.getWindowAncestor(myParent); final Point windowPos = window.getLocation(); pos.translate(windowPos.x, windowPos.y); final Insets windowInsets = window.getInsets();
public static void centerOnScreen(Window w, Window parent) { Rectangle r = new Rectangle(); if (parent == null) { r.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } else { r.setLocation(parent.getLocation()); r.setSize(parent.getSize()); } // Determine the new location of the alert int x = r.x + (r.width - w.getWidth()) / 2; int y = r.y + (r.height - w.getHeight()) / 2; // Move the alert w.setLocation(x, y); }
JButton button = (JButton)arg0.getSource(); Window frame = SwingUtilities.windowForComponent( button ); Rectangle bounds = frame.getLocation();
Component component = e.getComponent(); Window window = SwingUtilities.windowForComponent( component ); Point location = window.getLocation();
Window win = SwingUtilities.getWindowAncestor(someComponent); Point ownerLoc = win.getLocation();
/** Save the X and Y locations in Preferences node provided. */ public static void setSavedLocation( final Preferences pNode, final Window w) { Point where = w.getLocation(); int x = (int)where.getX(); pNode.putInt("mainwindow.x", Math.max(0, x)); int y = (int)where.getY(); pNode.putInt("mainwindow.y", Math.max(0, y)); }
/** Save the X and Y locations in Preferences node provided. */ public static void setSavedLocation( final Preferences pNode, final Window w) { Point where = w.getLocation(); int x = (int)where.getX(); pNode.putInt("mainwindow.x", Math.max(0, x)); int y = (int)where.getY(); pNode.putInt("mainwindow.y", Math.max(0, y)); }
/** Make the given {@link JToolBar} float. */ public void actionFloat(Component c) { Window w = SwingUtilities.getWindowAncestor(c); Point where = w.getLocation(); actionFloat(c, where.x, where.y); }
@RunsInCurrentThread @Nonnull private static Pair<Window, Point> ancestorAndLocation(final @Nonnull JToolBar toolBar) { Window window = getWindowAncestor(toolBar); return Pair.of(window, window.getLocation()); }
/** * <p/> * Returns the <code>Point</code> at which a window should be placed in * order to be staggered slightly from another "origin" window to * ensure that the title areas of both windows remain visible to the user. * </p> * * @param originWindow Window from which the staggered location will be calculated * * @return location staggered from the upper left location of the origin * window */ public static Point getPointForStaggering(Window originWindow) { Point origin = originWindow.getLocation(); Insets insets = originWindow.getInsets(); origin.x += insets.top; origin.y += insets.top; return origin; }
/** * <p/> * Returns the <code>Point</code> at which a window should be placed in * order to be staggered slightly from another "origin" window to * ensure that the title areas of both windows remain visible to the user. * </p> * * @param originWindow Window from which the staggered location will be calculated * * @return location staggered from the upper left location of the origin * window */ public static Point getPointForStaggering(Window originWindow) { Point origin = originWindow.getLocation(); Insets insets = originWindow.getInsets(); origin.x += insets.top; origin.y += insets.top; return origin; }
/** * <p/> * Returns the <code>Point</code> at which a window should be placed in * order to be staggered slightly from another "origin" window to * ensure that the title areas of both windows remain visible to the user. * </p> * * @param originWindow Window from which the staggered location will be calculated * * @return location staggered from the upper left location of the origin * window */ public static Point getPointForStaggering(Window originWindow) { Point origin = originWindow.getLocation(); Insets insets = originWindow.getInsets(); origin.x += insets.top; origin.y += insets.top; return origin; }
public void mousePressed( MouseEvent e ) { final Window win = SwingUtilities.getWindowAncestor( e.getComponent() ); final GraphicsDevice[] devs; if( win != null ) { initialMouse = e.getPoint(); SwingUtilities.convertPointToScreen( initialMouse, e.getComponent() ); initialLoc = win.getLocation(); devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); bounds = devs[ 0 ].getDefaultConfiguration().getBounds(); for( int i = 1; i < devs.length; i++ ) { bounds = bounds.union( devs[ i ].getDefaultConfiguration().getBounds() ); } } }
/** * Save the window attributes for a single window. * * @param window The window to save the attributes for */ private void saveWindowState(Window window) { // Only save state when window state was actually set during this // this session at least once if (!locationSet.contains(window) && window != primaryWindow) { return; } // Should still save whether it was open StateItem item = windows.get(window); Point location = window.getLocation(); String state = location.x+","+location.y; Dimension size = window.getSize(); state += ";"+size.width+","+size.height; state += ";"+(window.isVisible() ? "1" : "0"); settings.mapPut(SETTING, item.id, state); }
/** * Registers a new window. * If an old window with the same id is found, its position and size is set to the new window. * After that the old window is disposed. * * @param id the id of the window * @param window the window itself * @param <T> the type of the window * @return the window for chained calls */ public <T extends Window> T register(String id, T window) { if (windows.containsKey(id)) { Window oldWindow = windows.get(id); window.setLocation(oldWindow.getLocation()); window.setSize(oldWindow.getSize()); oldWindow.dispose(); } windows.put(id, window); return window; }
/** Returns whether one of the upper corners of the given window is * accessible. */ public static boolean onScreen(Window w) { return onScreen(w.getLocation()) || onScreen(new Point(w.getX() + w.getWidth()-1, w.getY())); }
@Override public void windowClosed(WindowEvent e) { if (e.getSource() == gui) { return; } popoutDisposed(getChannelFromWindow(e.getSource())); if (savePopoutAttributes) { Window window = e.getWindow(); dialogsAttributes.add(0, new LocationAndSize( window.getLocation(), window.getSize())); } }
@Override public void componentMoved(ComponentEvent evt) { Window owner = getOwner(); Point newLocation = owner.getLocation(); if (!newLocation.equals(oldLocation)) { setLocation( newLocation.x + (owner.getWidth() - getWidth()) / 2, newLocation.y + owner.getInsets().top); shiftBackLocation = null; oldLocation = newLocation; } } };
private void setInitialLocationAndSize(UserInfo dialog) { Point targetLocation = dummyWindow.getLocation(); if (dummyWindow.getWidth() == 0) { // Since size (and location) has not been set from the settings, // move window according to actual dialog size targetLocation.translate(- dialog.getWidth() / 2, - dialog.getHeight() / 2); } if (isLocationUsed(targetLocation)) { targetLocation.translate(20, 20); } dialog.setSize(dummyWindow.getSize()); dialog.setLocation(targetLocation); dialog.addComponentListener(closeListener); }