/** * Returns the device configuration associated with this * <code>Graphics2D</code>. * @return the device configuration */ public GraphicsConfiguration getDeviceConfiguration() { return GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); }
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getDefaultConfiguration(); BufferedImage buffy = config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
/** * Helps client code place components on the center of the screen. It * handles multiple monitor configuration correctly * * @param gconf the GraphicsConfiguration of the monitor * @param componentSize the size of the component * @return bounds of the centered component */ private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension componentSize) { if (gconf == null) { gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); } Rectangle bounds = gconf.getBounds(); return new Rectangle( bounds.x + ((bounds.width - componentSize.width) / 2), bounds.y + ((bounds.height - componentSize.height) / 2), componentSize.width, componentSize.height ); }
public static Rectangle[] getScreenBounds() { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices(); Rectangle[] screenBounds = new Rectangle[screenDevices.length]; for (int i = 0; i < screenDevices.length; i++) { GraphicsDevice screenDevice = screenDevices[i]; final GraphicsConfiguration defaultConfiguration = screenDevice.getDefaultConfiguration(); screenBounds[i] = defaultConfiguration.getBounds(); } return screenBounds; }
@Override public void open() { if (open) { return; } LOG.debug("Opening screen device {} with resolution {}", getName(), getResolution()); this.bounds = device .getDefaultConfiguration() .getBounds(); open = true; }
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // Use this if need to know about a device which is not the default... //GraphicsDevice lstGDs[] = ge.getScreenDevices(); GraphicsDevice device = ge.getDefaultScreenDevice(); GraphicsConfiguration cf = device.getDefaultConfiguration(); Rectangle bounds = cf.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);
static private ColorModel colorModel(int transparency) { ColorModel model; try { model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration() .getColorModel(transparency); } catch(HeadlessException he) { model = ColorModel.getRGBdefault(); } return model; }
/** * Helps client code place components on the center of the screen. It * handles multiple monitor configuration correctly * * @param gconf the GraphicsConfiguration of the monitor * @param componentSize the size of the component * @return bounds of the centered component */ private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension componentSize) { if (gconf == null) { gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); } Rectangle bounds = gconf.getBounds(); return new Rectangle( bounds.x + ((bounds.width - componentSize.width) / 2), bounds.y + ((bounds.height - componentSize.height) / 2), componentSize.width, componentSize.height ); }
private int initMonitors() { if (!SX.isHeadless()) { genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); gdevs = genv.getScreenDevices(); nMonitors = gdevs.length; Rectangle currentBounds; for (int i = 0; i < nMonitors; i++) { currentBounds = new Rectangle(gdevs[i].getDefaultConfiguration().getBounds()); if (null != allMonitors) { allMonitors = allMonitors.union(currentBounds);
for ( GraphicsDevice screen : getGraphicsDevices () ) GraphicsConfiguration gc = screen.getDefaultConfiguration (); Rectangle sb = gc.getBounds ();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); Rectangle bounds = new Rectangle(0, 0, 0, 0); if (gd != null) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); 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); }
private BufferedImage scale(BufferedImage source,double ratio) { int w = (int) (source.getWidth() * ratio); int h = (int) (source.getHeight() * ratio); BufferedImage bi = getCompatibleImage(w, h); Graphics2D g2d = bi.createGraphics(); double xScale = (double) w / source.getWidth(); double yScale = (double) h / source.getHeight(); AffineTransform at = AffineTransform.getScaleInstance(xScale,yScale); g2d.drawRenderedImage(source, at); g2d.dispose(); return bi; } private BufferedImage getCompatibleImage(int w, int h) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(w, h); return image; }
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = (int) rect.getMaxY() - f.getHeight();
private static Rectangle[] getScreens() { GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); List<Rectangle> screensList = new ArrayList<Rectangle>(); GraphicsDevice[] screenDevices = environment.getScreenDevices(); for (GraphicsDevice device : screenDevices) { GraphicsConfiguration configuration = device.getDefaultConfiguration(); Rectangle screenBounds = configuration.getBounds(); screensList.add(screenBounds); } return screensList.toArray(new Rectangle[screensList.size()]); }
/** * Get bounds of the screen. * * @return bounds of the screen */ public Rectangle getBounds() { return screen.getDefaultConfiguration().getBounds(); }
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle bounds = gc.getBounds(); JFrame gui = new JFrame("Changeable Resolution"); gui.setSize(bounds.width, bounds.height); gui.setLocation(bounds.x, bounds.y); gui.setDefaultCloseOperation(gui.EXIT_ON_CLOSE); gui.setVisible(true);
BufferedImage image = ImageIO.read ( url ); BufferedImage convertedImage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment (); GraphicsDevice gd = ge.getDefaultScreenDevice (); GraphicsConfiguration gc = gd.getDefaultConfiguration (); convertedImage = gc.createCompatibleImage (image.getWidth (), image.getHeight (), image.getTransparency () ); Graphics2D g2d = convertedImage.createGraphics (); g2d.drawImage ( image, 0, 0, image.getWidth (), image.getHeight (), null ); g2d.dispose()
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); BufferedImage bi = gc.createCompatibleImage(w, h);
GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); GraphicsDevice gd = null; int maxRes = Integer.MIN_VALUE; System.out.println(gds[i].getDefaultConfiguration().getBounds()); maxOffsetX = gds[i].getDefaultConfiguration().getBounds().x; maxOffsetY = gds[i].getDefaultConfiguration().getBounds().y; gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();