public static void centreWindow(Window frame) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); }
public void saveWindowPos(Window window) { WindowLocation pos = new WindowLocation(window.getClass().getSimpleName(), window.getX(), window.getY(), window.getWidth(), window.getHeight() ); windowPos.put(pos.getWindowId(), pos); partialSync(settings -> settings.windowPos = windowPos); }
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); }
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); }
/** * Updates the font metrics the first time we're displayed. */ @Override public void addNotify() { super.addNotify(); // Some LookAndFeels (e.g. WebLaF) for some reason have a 0x0 parent // window initially (perhaps something to do with them fading in?), // which will cause an exception from getGraphics(), so we must be // careful here. if (metricsNeverRefreshed) { Window parent = SwingUtilities.getWindowAncestor(this); if (parent!=null && parent.getWidth()>0 && parent.getHeight()>0) { refreshFontMetrics(getGraphics2D(getGraphics())); metricsNeverRefreshed = false; } } // Re-start parsing if we were removed from one container and added // to another if (parserManager!=null) { parserManager.restartParsing(); } }
@Override public void mouseDragged(MouseEvent e) { Point newPos = e.getPoint(); SwingUtilities.convertPointToScreen(newPos, SizeGrip.this); int xDelta = newPos.x - origPos.x; int yDelta = newPos.y - origPos.y; Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this); if (wind!=null) { // Should always be true if (getComponentOrientation().isLeftToRight()) { int w = wind.getWidth(); if (newPos.x>=wind.getX()) { w += xDelta; } int h = wind.getHeight(); if (newPos.y>=wind.getY()) { h += yDelta; } wind.setSize(w,h); } else { // RTL int newW = Math.max(1, wind.getWidth()-xDelta); int newH = Math.max(1, wind.getHeight()+yDelta); wind.setBounds(newPos.x, wind.getY(), newW, newH); } // invalidate()/validate() needed pre-1.6. wind.invalidate(); wind.validate(); } origPos.setLocation(newPos); }
@Override public void mouseClicked(MouseEvent e) { Window viewer = LogDialog.instance().getOwner(); // show the log window LogDialog.instance().setSize(800, 400); LogDialog.instance().setVisible(true); LogDialog.instance().setLocation(viewer.getLocationOnScreen().x + viewer.getWidth() / 2, viewer.getLocationOnScreen().y + viewer.getHeight() / 2); } });
@Override public void componentResized(ComponentEvent e) { setWidth(window.getWidth()); setHeight(window.getHeight()); } });
private void centerWindow(Window frame) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); }
/** * Centers a window on the primary display */ public static void centerOnPrimaryScreen(Window toplevel) { Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize(); toplevel.setLocation((screenRes.width - toplevel.getWidth()) / 2, (screenRes.height - toplevel.getHeight()) / 2); }
@Override public void recive(Window wnd) { if( wnd==null )return; int cw = wnd.getWidth(); int ch = wnd.getHeight(); if( cw<w || ch<h ){ int tw = Math.max(cw, w); int th = Math.max(ch, h); wnd.setSize(tw, th); } } };
public static void centreWindow(Window frame) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); }
/** * Center a window on screen. * * @param w * the window to center on screen. */ public static void centerOnScreen(Window w) { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); w.setLocation((screenDim.width - w.getWidth()) / 2, (screenDim.height - w .getHeight()) / 2); }
/** * Center a window on screen. * * @param w * the window to center on screen. */ public static void centerOnScreen(Window w) { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); w.setLocation((screenDim.width - w.getWidth()) / 2, (screenDim.height - w.getHeight()) / 2); }
public static void showCenterScreen(Window window) { try { Rectangle bound = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); window.setLocation(bound.x + (bound.width - window.getWidth()) / 2, bound.y + (bound.height - window.getHeight()) / 2); } catch (Exception e) { LOGGER.error("Cannot center the window to the screen", e); //$NON-NLS-1$ } window.setVisible(true); }
/** We can't get any motion events on an empty frame. */ private boolean isEmptyFrame(Window w) { Insets insets = AWT.getInsets(w); return insets.top + insets.bottom == w.getHeight() || insets.left + insets.right == w.getWidth(); } }
public static void ensureWindowIsVisible( Window w ) { int width = w.getWidth(); int height = w.getHeight(); Toolkit toolkit = Toolkit.getDefaultToolkit(); GraphicsConfiguration gc = w.getGraphicsConfiguration(); Insets screenInsets = toolkit.getScreenInsets( gc ); Rectangle screenSize = gc.getBounds(); w.setLocation( Math.max( screenInsets.left, Math.min( w.getX(), screenSize.width - screenInsets.right - width ) ), Math.max( screenInsets.top, Math.min( w.getY(), screenSize.height - screenInsets.bottom - height ) ) ); }
/** * Packs, centers, and shows the specified window on the screen. * @param window the window to pack, center, and show * @param center {@code true} if the window must be centered; {@code false} otherwise */ private void packCenterShow(Window window, boolean center) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); window.pack(); if (center) { window.setLocation((screenSize.width - window.getWidth()) / 2, (screenSize.height - window.getHeight()) / 2); } window.setVisible(true); }
@RunsInCurrentThread static @Nonnull Point absoluteCenterOf(@Nonnull Window window) { Insets insets = window.getInsets(); int w = window.getWidth() - (insets.left + insets.right); int h = window.getHeight() - (insets.top + insets.bottom); int x = window.getX() + insets.left; int y = window.getY() + insets.top; return new Point(x + (w / 2), y + (h / 2)); }
public void display() { setSize((int)(getOwner().getWidth() * 0.7), (int)(getOwner().getHeight() * 0.7)); SwingUtil.center(getOwner(), this); setVisible(true); }