public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(getOwner().getGraphicsConfiguration()); int taskBarSize = scnMax.bottom; int usableScreenHeight = screenSize.height - taskBarSize - 50; if (size.height > (usableScreenHeight)) { size.height = usableScreenHeight; } return size; }
Insets insets = toolkit.getScreenInsets(gconf);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Insets scnMax = Toolkit.getDefaultToolkit(). getScreenInsets(dialog.getGraphicsConfiguration()); int taskBarSize = scnMax.bottom; panel.setLayout(new GridBagLayout());
Insets insets = toolkit.getScreenInsets(gconf);
public static void keepComponentInsideScreen(int centerX, int centerY, Component component) { Dimension screenDim = component.getToolkit().getScreenSize(); GraphicsConfiguration g = component.getGraphicsConfiguration(); if (g != null) { Insets insets = component.getToolkit().getScreenInsets(g); // no usable space like toolbar boolean setLocation = false; if (centerX + component.getWidth() > screenDim.width - insets.right) { centerX = (screenDim.width - insets.right) - component.getWidth(); setLocation = true; } else if (centerX < insets.left) { centerX = insets.left; setLocation = true; } if (centerY + component.getHeight() > screenDim.height - insets.bottom) { centerY = (screenDim.height - insets.bottom) - component.getHeight(); setLocation = true; } else if (centerY < insets.top) { centerY = insets.top; setLocation = true; } if (setLocation) { component.setLocation(centerX, centerY); } } else { System.out.println("GuiDisplayUtil::keepComponentInsideScreen -> no GraphicsConfiguration"); } }
final Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets( getGraphicsConfiguration()); final int taskBarSize = scnMax.bottom;
private static Rectangle getUsableDeviceBounds(GraphicsConfiguration gc) { Rectangle bounds = gc.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
private static Rectangle getUsableDeviceBounds(GraphicsConfiguration gc) { Rectangle bounds = gc.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
/** Return the visible bounds for the graphics configuration. This will * exclude any permanent menu bar or dashboard decorations. */ public static Rectangle getVisibleBounds(GraphicsConfiguration gc) { Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle r = gc.getBounds(); r.x += insets.left; r.y += insets.top; r.width -= insets.left + insets.right; r.height -= insets.top + insets.bottom; return r; }
private static Rectangle getUsableDeviceBounds(GraphicsConfiguration gc) { Rectangle bounds = gc.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
public static Rectangle getEffectiveScreenBounds(GraphicsConfiguration config) { Rectangle bounds = config.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config); Debugging.println("screenbounds", "%s %s", bounds, insets); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.right; bounds.height -= insets.bottom; return bounds; }
private static Insets[] getInsets() { GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); List<Insets> insetsList = new ArrayList<Insets>(); GraphicsDevice[] screenDevices = environment.getScreenDevices(); for (GraphicsDevice device : screenDevices) { GraphicsConfiguration configuration = device.getDefaultConfiguration(); Rectangle screenBounds = configuration.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(configuration); insetsList.add(insets); } return insetsList.toArray(new Insets[insetsList.size()]); }
/** * Computes the screen's insets for the specified window and returns them. * <p> * While this might seem strange, screen insets can change from one window * to another. For example, on X11 windowing systems, there is no guarantee that * a window will be displayed on the same screen, let alone computer, as the one * the application is running on. * </p> * @param window the window for which screen insets should be computed. * @return the screen's insets for the specified window */ public static Insets getScreenInsets(Window window) { return Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration()); }
public static Rectangle getScreenBounds(final GraphicsConfiguration graphicsConfiguration) { final Toolkit defaultToolkit = Toolkit.getDefaultToolkit(); final Insets screenInsets = defaultToolkit.getScreenInsets(graphicsConfiguration); final Rectangle screenBounds = graphicsConfiguration.getBounds(); final Point screenLocation = screenBounds.getLocation(); final Dimension screenSize = screenBounds.getSize(); final int screenWidth = screenSize.width - screenInsets.left - screenInsets.right; final int screenHeight = screenSize.height - screenInsets.top - screenInsets.bottom; return new Rectangle(screenLocation.x + screenInsets.left, screenLocation.y + screenInsets.top, screenWidth, screenHeight); }
private static Rectangle configurarMaximizar(){ GraphicsDevice monitorAtual = MouseInfo.getPointerInfo().getDevice(); Rectangle bounds = monitorAtual.getDefaultConfiguration().getBounds(); GraphicsConfiguration gcc[] = monitorAtual.getConfigurations(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gcc[0]); Rectangle newBounds = new Rectangle(bounds.width - (screenInsets.left + screenInsets.right), bounds.height - (screenInsets.top + screenInsets.bottom)); newBounds.x = monitorAtual.getDefaultConfiguration().getBounds().x + screenInsets.left; newBounds.y = monitorAtual.getDefaultConfiguration().getBounds().y + screenInsets.top; return newBounds; }
public ScrollPopupMenu(Point screenPt) { super(); scroll = new JScrollPane(); panelMenus = new JPanel(); panelMenus.setLayout(new GridLayout(0, 1)); scroll.setViewportView(panelMenus); scroll.setBorder(null); GraphicsConfiguration gc = WinUtil.getGraphicsDeviceConfig(screenPt); scroll.setMaximumSize(new Dimension(scroll.getMaximumSize().width, this.getToolkit().getScreenSize().height - this.getToolkit().getScreenInsets(gc).top - this.getToolkit().getScreenInsets(gc).bottom - 4)); super.add(scroll); }
/** * Calculates default location for the specified window. * @return default location for the window * @param window the window location is calculated for. * It should not be null. */ public static Point defaultLocation(Window window) { GraphicsConfiguration gc = window.getGraphicsConfiguration(); Rectangle bounds = gc.getBounds(); Insets insets = window.getToolkit().getScreenInsets(gc); int x = bounds.x + insets.left; int y = bounds.y + insets.top; return new Point(x, y); }
protected void validateMaximizedBounds() { Frame frame = getFrame(); if (frame != null && !wasMaximizeError) { GraphicsConfiguration gc = frame.getGraphicsConfiguration(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle maxBounds = gc.getBounds(); maxBounds.x = Math.max(0, screenInsets.left); maxBounds.y = Math.max(0, screenInsets.top); maxBounds.width -= (screenInsets.left + screenInsets.right); maxBounds.height -= (screenInsets.top + screenInsets.bottom); frame.setMaximizedBounds(maxBounds); } }
public static void moveToCenterScreen(JFrame frame) { Toolkit kit = frame.getToolkit(); GraphicsDevice[] gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); Insets in = kit.getScreenInsets(gs[0].getDefaultConfiguration()); Dimension d = kit.getScreenSize(); int max_width = (d.width - in.left - in.right); int max_height = (d.height - in.top - in.bottom); frame.setLocation((int) (max_width - frame.getWidth()) / 2, (int) (max_height - frame.getHeight() ) / 2); }
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 ) ) ); }