Gets the maximal screen height and the total screen width, assuming that multiple monitors are aligned horizontally. - Java 2D Graphics

Java examples for 2D Graphics:Screen

Description

Gets the maximal screen height and the total screen width, assuming that multiple monitors are aligned horizontally.

Demo Code


//package com.java2s;

import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

public class Main {
    /**/*w ww .j  a v  a 2s  . c  o  m*/
     * Gets the maximal screen height and the total screen width, assuming that
     * multiple monitors are aligned horizontally.
     *
     * @return
     */
    public static Dimension getMultiMonitorScreenSize() {
        Dimension screenSize = new Dimension();

        GraphicsEnvironment gEnvironment = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = gEnvironment.getScreenDevices();
        for (GraphicsDevice device : devices) {
            DisplayMode displayMode = device.getDisplayMode();
            screenSize.height = Math.max(displayMode.getHeight(),
                    screenSize.height);
            screenSize.width += displayMode.getWidth();
        }

        return screenSize;
    }
}

Related Tutorials