Java Code Examples for java.awt.GraphicsConfiguration#getBounds()
The following examples show how to use
java.awt.GraphicsConfiguration#getBounds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiUtils.java From sc2gears with Apache License 2.0 | 6 votes |
/** * Resizes a window by setting its bounds to maximum that fits inside the default screen having the specified margin around it, * and centers the window on the screen. * * <p>The implementation takes the screen insets (for example space occupied by task bar) into account.</p> * * @param window window to be resized * @param margin margin to leave around the window * @param maxSize optional parameter defining a maximum size */ public static void maximizeWindowWithMargin( final Window window, final int margin, final Dimension maxSize ) { final GraphicsConfiguration defaultConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); final Rectangle bounds = defaultConfiguration.getBounds(); final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets( defaultConfiguration ); final int width = bounds.width - insets.left - insets.right - ( margin << 1 ); final int height = bounds.height - insets.top - insets.bottom - ( margin << 1 ); if ( maxSize == null ) window.setSize( width, height ); else window.setSize( Math.min( width, maxSize.width ), Math.min( height, maxSize.height ) ); GeneralUtils.centerWindow( window ); }
Example 2
Source File: WindowResizingOnSetLocationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void initScreenBounds() { GraphicsDevice[] devices = GraphicsEnvironment .getLocalGraphicsEnvironment() .getScreenDevices(); screenBounds = new Rectangle[devices.length]; scales = new double[devices.length][2]; for (int i = 0; i < devices.length; i++) { GraphicsConfiguration gc = devices[i].getDefaultConfiguration(); screenBounds[i] = gc.getBounds(); AffineTransform tx = gc.getDefaultTransform(); scales[i][0] = tx.getScaleX(); scales[i][1] = tx.getScaleY(); } for (int i = 0; i < devices.length; i++) { for (int j = i + 1; j < devices.length; j++) { if (scales[i][0] != scales[j][0] || scales[i][1] != scales[j][1]) { screen1 = i; screen2 = j; } } } }
Example 3
Source File: ClientUI.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private GraphicsConfiguration getIntersectingDisplay(final Rectangle bounds) { GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); for (GraphicsDevice gd : gds) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); final Rectangle displayBounds = gc.getBounds(); if (displayBounds.intersects(bounds)) { return gc; } } return null; }
Example 4
Source File: bug8071705.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) { GraphicsDevice correctDevice = null; if (devices.length < 2) { return correctDevice; } Toolkit toolkit = Toolkit.getDefaultToolkit(); Rectangle screenBounds = new Rectangle(toolkit.getScreenSize()); int halfScreen = screenBounds.height/2; for(int i = 0; i < devices.length; i++) { if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { GraphicsConfiguration conf = devices[i].getDefaultConfiguration(); Rectangle bounds = conf.getBounds(); if (bounds.y >= halfScreen) { // found correctDevice = devices[i]; break; } } } return correctDevice; }
Example 5
Source File: NbiDialog.java From netbeans with Apache License 2.0 | 6 votes |
public void setVisible(boolean visible) { if (owner == null) { final GraphicsDevice screen = GraphicsEnvironment. getLocalGraphicsEnvironment(). getScreenDevices()[0]; final GraphicsConfiguration config = screen.getDefaultConfiguration(); final int screenWidth = config.getBounds().width; final int screenHeight = config.getBounds().height; setLocation( (screenWidth - getSize().width) / 2, (screenHeight - getSize().height) / 2); } else { setLocation( owner.getLocation().x + DIALOG_FRAME_WIDTH_DELTA, owner.getLocation().y + DIALOG_FRAME_WIDTH_DELTA); } super.setVisible(visible); }
Example 6
Source File: X11GraphicsDevice.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private DisplayMode getDefaultDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); return new DisplayMode(r.width, r.height, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN); }
Example 7
Source File: TooltipWindow.java From netbeans with Apache License 2.0 | 5 votes |
public void show(Point location) { Rectangle screenBounds = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gds = ge.getScreenDevices(); for (GraphicsDevice device : gds) { GraphicsConfiguration gc = device.getDefaultConfiguration(); screenBounds = gc.getBounds(); if (screenBounds.contains(location)) { break; } } // showing the popup tooltip cp = new TooltipContentPanel(master.getTextComponent()); Window w = SwingUtilities.windowForComponent(master.getTextComponent()); contentWindow = new JWindow(w); contentWindow.add(cp); contentWindow.pack(); Dimension dim = contentWindow.getSize(); if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) { dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER); } if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) { dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER); } contentWindow.setSize(dim); contentWindow.setLocation(location.x, location.y - 1); // slight visual adjustment contentWindow.setVisible(true); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK); w.addWindowFocusListener(this); contentWindow.addWindowFocusListener(this); }
Example 8
Source File: X11GraphicsDevice.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private DisplayMode getDefaultDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); return new DisplayMode(r.width, r.height, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN); }
Example 9
Source File: X11GraphicsDevice.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private DisplayMode getDefaultDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); return new DisplayMode(r.width, r.height, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN); }
Example 10
Source File: SunGraphicsEnvironment.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Return the bounds of a GraphicsDevice, less its screen insets. * See also java.awt.GraphicsEnvironment.getUsableBounds(); */ public static Rectangle getUsableBounds(GraphicsDevice gd) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle usableBounds = gc.getBounds(); usableBounds.x += insets.left; usableBounds.y += insets.top; usableBounds.width -= (insets.left + insets.right); usableBounds.height -= (insets.top + insets.bottom); return usableBounds; }
Example 11
Source File: InternalUtilities.java From LGoodDatePicker with MIT License | 5 votes |
/** * getScreenTotalArea, This returns the total area of the screen. (The total area includes any * task bars.) This function accounts for multi-monitor setups. If a window is supplied, then * the the monitor that contains the window will be used. If a window is not supplied, then the * primary monitor will be used. */ static public Rectangle getScreenTotalArea(Window windowOrNull) { Rectangle bounds; if (windowOrNull == null) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds(); } else { GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration(); bounds = gc.getBounds(); } return bounds; }
Example 12
Source File: SunGraphicsEnvironment.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Return the bounds of a GraphicsDevice, less its screen insets. * See also java.awt.GraphicsEnvironment.getUsableBounds(); */ public static Rectangle getUsableBounds(GraphicsDevice gd) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle usableBounds = gc.getBounds(); usableBounds.x += insets.left; usableBounds.y += insets.top; usableBounds.width -= (insets.left + insets.right); usableBounds.height -= (insets.top + insets.bottom); return usableBounds; }
Example 13
Source File: X11GraphicsDevice.java From hottub with GNU General Public License v2.0 | 5 votes |
private DisplayMode getDefaultDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); return new DisplayMode(r.width, r.height, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN); }
Example 14
Source File: SunGraphicsEnvironment.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Return the bounds of a GraphicsDevice, less its screen insets. * See also java.awt.GraphicsEnvironment.getUsableBounds(); */ public static Rectangle getUsableBounds(GraphicsDevice gd) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle usableBounds = gc.getBounds(); usableBounds.x += insets.left; usableBounds.y += insets.top; usableBounds.width -= (insets.left + insets.right); usableBounds.height -= (insets.top + insets.bottom); return usableBounds; }
Example 15
Source File: bug8071705.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private static Rectangle setLocation(JFrame frame, GraphicsDevice device) { GraphicsConfiguration conf = device.getDefaultConfiguration(); Rectangle bounds = conf.getBounds(); // put just below half screen int x = bounds.x + bounds.width/2; int y = bounds.y + bounds.height/2; frame.setLocation(x, y); return bounds; }
Example 16
Source File: bug8016356.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { // Windows only test if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { // Retrieving top edge of Desktop GraphicsConfiguration grConf = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Rectangle scrRect = grConf.getBounds(); Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf); scrTop = scrRect.y + scrInsets.top; color = new Color(0, 255, 0); SwingUtilities.invokeAndWait(() -> { createAndShowUI(); }); try { Robot robot = new Robot(); robot.setAutoDelay(500); robot.setAutoWaitForIdle(true); robot.delay(1000); // Resizing a window to invoke Windows Snap feature readFrameInfo(); robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(frLoc.x + frSize.width / 2, scrTop); robot.mouseRelease(InputEvent.BUTTON1_MASK); // Retrieving the color of window expanded area readFrameInfo(); Insets insets = frame.getInsets(); Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2, frLoc.y + frSize.height - insets.bottom - 1); frame.dispose(); if (!bgColor.equals(color)) { throw new RuntimeException("TEST FAILED: got " + bgColor + " instead of " + color); } System.out.println("TEST PASSED!"); } catch (AWTException ex) { throw new RuntimeException("TEST FAILED!"); } } }
Example 17
Source File: bug8016356.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { // Windows only test if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { // Retrieving top edge of Desktop GraphicsConfiguration grConf = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Rectangle scrRect = grConf.getBounds(); Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf); scrTop = scrRect.y + scrInsets.top; color = new Color(0, 255, 0); SwingUtilities.invokeAndWait(() -> { createAndShowUI(); }); try { Robot robot = new Robot(); robot.setAutoDelay(500); robot.setAutoWaitForIdle(true); robot.delay(1000); // Resizing a window to invoke Windows Snap feature readFrameInfo(); robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(frLoc.x + frSize.width / 2, scrTop); robot.mouseRelease(InputEvent.BUTTON1_MASK); // Retrieving the color of window expanded area readFrameInfo(); Insets insets = frame.getInsets(); Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2, frLoc.y + frSize.height - insets.bottom - 1); frame.dispose(); if (!bgColor.equals(color)) { throw new RuntimeException("TEST FAILED: got " + bgColor + " instead of " + color); } System.out.println("TEST PASSED!"); } catch (AWTException ex) { throw new RuntimeException("TEST FAILED!"); } } }
Example 18
Source File: MultiScreenLocationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws AWTException { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gds = ge.getScreenDevices(); if (gds.length < 2) { System.out.println("It's a multiscreen test... skipping!"); return; } for (int i = 0; i < gds.length; ++i) { GraphicsDevice gd = gds[i]; GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screen = gc.getBounds(); Robot robot = new Robot(gd); // check Robot.mouseMove() robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y); Point mouse = MouseInfo.getPointerInfo().getLocation(); Point point = screen.getLocation(); point.translate(mouseOffset.x, mouseOffset.y); if (!point.equals(mouse)) { throw new RuntimeException(getErrorText("Robot.mouseMove", i)); } // check Robot.getPixelColor() Frame frame = new Frame(gc); frame.setUndecorated(true); frame.setSize(100, 100); frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y); frame.setBackground(color); frame.setVisible(true); robot.waitForIdle(); Rectangle bounds = frame.getBounds(); if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) { throw new RuntimeException(getErrorText("Robot.getPixelColor", i)); } // check Robot.createScreenCapture() BufferedImage image = robot.createScreenCapture(bounds); int rgb = color.getRGB(); if (image.getRGB(0, 0) != rgb || image.getRGB(image.getWidth() - 1, 0) != rgb || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb || image.getRGB(0, image.getHeight() - 1) != rgb) { throw new RuntimeException( getErrorText("Robot.createScreenCapture", i)); } frame.dispose(); } System.out.println("Test PASSED!"); }
Example 19
Source File: MultiScreenLocationTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws AWTException { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gds = ge.getScreenDevices(); if (gds.length < 2) { System.out.println("It's a multiscreen test... skipping!"); return; } for (int i = 0; i < gds.length; ++i) { GraphicsDevice gd = gds[i]; GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screen = gc.getBounds(); Robot robot = new Robot(gd); // check Robot.mouseMove() robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y); Point mouse = MouseInfo.getPointerInfo().getLocation(); Point point = screen.getLocation(); point.translate(mouseOffset.x, mouseOffset.y); if (!point.equals(mouse)) { throw new RuntimeException(getErrorText("Robot.mouseMove", i)); } // check Robot.getPixelColor() Frame frame = new Frame(gc); frame.setUndecorated(true); frame.setSize(100, 100); frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y); frame.setBackground(color); frame.setVisible(true); robot.waitForIdle(); Rectangle bounds = frame.getBounds(); if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) { throw new RuntimeException(getErrorText("Robot.getPixelColor", i)); } // check Robot.createScreenCapture() BufferedImage image = robot.createScreenCapture(bounds); int rgb = color.getRGB(); if (image.getRGB(0, 0) != rgb || image.getRGB(image.getWidth() - 1, 0) != rgb || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb || image.getRGB(0, image.getHeight() - 1) != rgb) { throw new RuntimeException( getErrorText("Robot.createScreenCapture", i)); } frame.dispose(); } System.out.println("Test PASSED!"); }
Example 20
Source File: MultiScreenLocationTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws AWTException { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gds = ge.getScreenDevices(); if (gds.length < 2) { System.out.println("It's a multiscreen test... skipping!"); return; } for (int i = 0; i < gds.length; ++i) { GraphicsDevice gd = gds[i]; GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screen = gc.getBounds(); Robot robot = new Robot(gd); // check Robot.mouseMove() robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y); Point mouse = MouseInfo.getPointerInfo().getLocation(); Point point = screen.getLocation(); point.translate(mouseOffset.x, mouseOffset.y); if (!point.equals(mouse)) { throw new RuntimeException(getErrorText("Robot.mouseMove", i)); } // check Robot.getPixelColor() Frame frame = new Frame(gc); frame.setUndecorated(true); frame.setSize(100, 100); frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y); frame.setBackground(color); frame.setVisible(true); robot.waitForIdle(); Rectangle bounds = frame.getBounds(); if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) { throw new RuntimeException(getErrorText("Robot.getPixelColor", i)); } // check Robot.createScreenCapture() BufferedImage image = robot.createScreenCapture(bounds); int rgb = color.getRGB(); if (image.getRGB(0, 0) != rgb || image.getRGB(image.getWidth() - 1, 0) != rgb || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb || image.getRGB(0, image.getHeight() - 1) != rgb) { throw new RuntimeException( getErrorText("Robot.createScreenCapture", i)); } frame.dispose(); } System.out.println("Test PASSED!"); }