Java tutorial
//package com.java2s; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Toolkit; public class Main { /** * The bounds of the primary screen (adjusted for insets). */ public static Rectangle SCREEN_SIZE_PRIMARY; /** * The virtual bounds of all screens together (adjusted for insets). */ public static Rectangle SCREEN_SIZE_TOTAL; /** * Updates {@link #SCREEN_SIZE_PRIMARY } and {@link #SCREEN_SIZE_TOTAL} */ public static void calculateScreenSizes() { Rectangle totalBounds = new Rectangle(); Rectangle primaryBounds = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; if (gd == ge.getDefaultScreenDevice()) { primaryBounds = new Rectangle(); } GraphicsConfiguration[] gc = gd.getConfigurations(); for (int i = 0; i < gc.length; i++) { Rectangle bounds = gc[i].getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc[i]); bounds.x += screenInsets.left; bounds.y += screenInsets.top; bounds.height -= screenInsets.bottom; bounds.width -= screenInsets.right; totalBounds = totalBounds.union(bounds); if (primaryBounds != null) { primaryBounds = primaryBounds.union(bounds); } } if (primaryBounds != null) { SCREEN_SIZE_PRIMARY = primaryBounds; primaryBounds = null; } } SCREEN_SIZE_TOTAL = totalBounds; } }