Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Toolkit; public class Main { /** * Gets the insets of the screen. * <p> * <b>Attention: </b>Due to <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6899304">Java bug 6899304</a> * this method only returns correct insets values for the primary screen device. For other screen devices empty insets * will be returned. In Windows environments these circumstances (task bar on a none primary screen) will be very rare * and therefore ignored until the bug will be fixed in a future Java version. * </p> * * @param screenDevice * a screen thats {@link GraphicsConfiguration} will be used to determine the insets * @return the insets of this toolkit's screen, in pixels, if the given screen device is the primary screen, otherwise * empty insets * @see Toolkit#getScreenInsets(GraphicsConfiguration) */ public static Insets getScreenInsets(GraphicsDevice screenDevice) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // <bko 2012-02-29> // "Fix" for Sun bug 6899304 ("java.awt.Toolkit.getScreenInsets(GraphicsConfiguration) returns incorrect values") // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6699851 if (screenDevice == ge.getDefaultScreenDevice()) { // only return Toolkit.getScreenInsets for primary screen device return Toolkit.getDefaultToolkit().getScreenInsets(screenDevice.getDefaultConfiguration()); } else { // return empty insets for other screen devices return new Insets(0, 0, 0, 0); } // </bko> } }