Example usage for java.awt GraphicsConfiguration getBounds

List of usage examples for java.awt GraphicsConfiguration getBounds

Introduction

In this page you can find the example usage for java.awt GraphicsConfiguration getBounds.

Prototype

public abstract Rectangle getBounds();

Source Link

Document

Returns the bounds of the GraphicsConfiguration in the device coordinates.

Usage

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = env.getMaximumWindowBounds();
    System.out.println("Screen Bounds: " + bounds);

    GraphicsDevice screen = env.getDefaultScreenDevice();
    GraphicsConfiguration config = screen.getDefaultConfiguration();
    System.out.println("Screen Size  : " + config.getBounds());

    JFrame frame = new JFrame("Frame Info");
    System.out.println("Frame Insets : " + frame.getInsets());

    frame.setSize(200, 200);/*from w  ww . ja  v  a2s  .co m*/
    System.out.println("Frame Insets : " + frame.getInsets());
    frame.setVisible(true);

    System.out.println("Frame Size   : " + frame.getSize());
    System.out.println("Frame Insets : " + frame.getInsets());
    System.out.println("Content Size : " + frame.getContentPane().getSize());
}

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
    GraphicsConfiguration[] configurations = defaultScreen.getConfigurations();
    System.out.println("Default screen device: " + defaultScreen.getIDstring());
    for (int i = 0; i < configurations.length; i++) {
        System.out.println("  Configuration " + (i + 1));
        GraphicsConfiguration c = configurations[i];
        System.out.println("  " + c.getColorModel());
        System.out.println("  " + c.getBounds());
        System.out.println("  " + c.getBufferCapabilities());
        System.out.println("  " + c.getDefaultTransform());
        System.out.println("  " + c.getDevice());
    }//from   www.j  a  v a2  s.  c o m
}

From source file:Main.java

private static void centerOn(JFrame f, GraphicsConfiguration gc) {
    Rectangle bounds = gc.getBounds();
    int x = bounds.x + ((bounds.width - f.getWidth()) / 2);
    int y = bounds.y + ((bounds.height - f.getHeight()) / 2);
    f.setLocation(x, y);//ww w.ja v a 2s.com
}

From source file:Main.java

public static Rectangle computeVirtualGraphicsBounds() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        virtualBounds = virtualBounds.union(gc.getBounds());
    }/*ww w. jav a2 s .c  o m*/
    return virtualBounds;
}

From source file:Main.java

/**
 * Returns the GraphicsConfiguration for a point.
 *///from  www  .j  av  a 2 s.com
public static GraphicsConfiguration getGraphicsConfiguration(Component aComp, int anX, int aY) {
    // Get initial GC from component (if available) and point on screen
    GraphicsConfiguration gc = aComp != null ? aComp.getGraphicsConfiguration() : null;
    Point spoint = getScreenLocation(aComp, anX, aY);

    // Replace with alternate GraphicsConfiguration if point on another screen
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration dgc = gd.getDefaultConfiguration();
            if (dgc.getBounds().contains(spoint.x, spoint.y)) {
                gc = dgc;
                break;
            }
        }
    }

    // Return GraphicsConfiguration
    return gc;
}

From source file:Main.java

private static Rectangle getScreenBounds(Window aWindow) {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();

    if (aWindow == null)
        return devices[0].getDefaultConfiguration().getBounds();

    Rectangle bounds = aWindow.getBounds();
    int centerX = (int) bounds.getCenterX();
    int centerY = (int) bounds.getCenterY();

    for (GraphicsDevice device : devices) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        Rectangle rect = gc.getBounds();
        if (rect.contains(centerX, centerY))
            return rect;
    }// ww w  . java 2s . co m

    return null;
}

From source file:Main.java

/**
 * Get the full screen size recognizing multiple monitor.
 * /*  w  ww  . j av  a2  s.c  o  m*/
 * @return full screen size
 */
public static Dimension getFullScreenSize() {
    Rectangle2D result = new Rectangle2D.Double();
    GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (GraphicsDevice gd : localGE.getScreenDevices()) {
        for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
            Rectangle2D.union(result, graphicsConfiguration.getBounds(), result);
        }
    }
    return new Dimension((int) result.getWidth(), (int) result.getHeight());
}

From source file:Main.java

/**
 * Returns the screen bounds for a component location (or screen location if component null).
 *//*  ww w.  j a  va  2 s.c o m*/
public static Rectangle getScreenBounds(Component aComp, int anX, int aY, boolean doInset) {
    GraphicsConfiguration gc = getGraphicsConfiguration(aComp, anX, aY);
    Rectangle rect = gc != null ? gc.getBounds() : new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    Insets ins = doInset && gc != null ? Toolkit.getDefaultToolkit().getScreenInsets(gc) : null;
    if (ins != null) {
        int lt = ins.left, rt = ins.right, tp = ins.top, bt = ins.bottom;
        rect.setBounds(rect.x + lt, rect.y + tp, rect.width - lt - rt, rect.height - tp - bt);
    }
    return rect;
}

From source file:Main.java

public static void showOnSameScreenAsMouseCenter(Container frame) {
    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();

    GraphicsDevice device;/* w ww.  j a  v  a2  s.c o  m*/

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice lstGDs[] = ge.getScreenDevices();

    ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length);

    for (GraphicsDevice gd : lstGDs) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screenBounds = gc.getBounds();

        if (screenBounds.contains(mouseLocation)) {
            lstDevices.add(gd);
        }
    }

    if (lstDevices.size() > 0) {
        device = lstDevices.get(0);
    } else {
        device = ge.getDefaultScreenDevice();
    }

    Rectangle bounds = device.getDefaultConfiguration().getBounds();
    frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2,
            bounds.y + bounds.height / 2 - frame.getHeight() / 2);
}

From source file:Main.java

public static GraphicsConfiguration getGraphicsConfigurationForCurrentLocation(Window window) {
    GraphicsConfiguration ownedConfig = window.getGraphicsConfiguration();
    Point currLocation = window.getLocation();
    // Shortcut for "owned" case
    if (ownedConfig.getBounds().contains(currLocation))
        return ownedConfig;

    // Search for the right screen
    GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice screen : screens)
        for (GraphicsConfiguration config : screen.getConfigurations())
            if (config.getBounds().contains(currLocation))
                return config;

    // If none found, lets return the "owned" one
    return ownedConfig;
}