merge All Screens via GraphicsDevice - Java java.awt

Java examples for java.awt:GraphicsDevice

Description

merge All Screens via GraphicsDevice

Demo Code


//package com.java2s;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(mergeAllScreens());
    }/*  w w w  .  j  ava2  s .  c  o  m*/

    /**
     * @return a rectangle consisting of a union of the rectangles of all
     * screens
     */
    public static Rectangle mergeAllScreens() {
        Rectangle virtualBounds = new Rectangle();
        final GraphicsEnvironment ge = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        for (final GraphicsDevice gd : ge.getScreenDevices()) {
            for (final GraphicsConfiguration element : gd
                    .getConfigurations()) {
                virtualBounds = virtualBounds.union(element.getBounds());
            }
        }
        return virtualBounds;
    }
}

Related Tutorials