Here you can find the source of getUsableScreenBounds(GraphicsConfiguration gconf)
Parameter | Description |
---|---|
gconf | the GraphicsConfiguration of the monitor |
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf)
//package com.java2s; //License from project: Apache License import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.KeyboardFocusManager; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.SwingUtilities; public class Main { /**/*from w w w.java 2s.c o m*/ * Returns the usable area of the screen where applications can place its * windows. The method subtracts from the screen the area of taskbars, * system menus and the like. The screen this method applies to is the one * which is considered current, ussually the one where the current input * focus is. * * @return the rectangle of the screen where one can place windows * * @since 2.5 */ public static Rectangle getUsableScreenBounds() { return getUsableScreenBounds(getCurrentGraphicsConfiguration()); } /** * Returns the usable area of the screen where applications can place its * windows. The method subtracts from the screen the area of taskbars, * system menus and the like. * * @param gconf the GraphicsConfiguration of the monitor * @return the rectangle of the screen where one can place windows * * @since 2.5 */ public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) { if (gconf == null) { gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } Rectangle bounds = new Rectangle(gconf.getBounds()); String str; str = System.getProperty("netbeans.screen.insets"); // NOI18N if (str != null) { StringTokenizer st = new StringTokenizer(str, ", "); // NOI18N if (st.countTokens() == 4) { try { bounds.y = Integer.parseInt(st.nextToken()); bounds.x = Integer.parseInt(st.nextToken()); bounds.height -= (bounds.y + Integer.parseInt(st.nextToken())); bounds.width -= (bounds.x + Integer.parseInt(st.nextToken())); } catch (NumberFormatException ex) { Logger.getAnonymousLogger().log(Level.WARNING, null, ex); } } return bounds; } str = System.getProperty("netbeans.taskbar.height"); // NOI18N if (str != null) { bounds.height -= Integer.getInteger(str, 0).intValue(); return bounds; } try { Toolkit toolkit = Toolkit.getDefaultToolkit(); Insets insets = toolkit.getScreenInsets(gconf); bounds.y += insets.top; bounds.x += insets.left; bounds.height -= (insets.top + insets.bottom); bounds.width -= (insets.left + insets.right); } catch (Exception ex) { Logger.getAnonymousLogger().log(Level.WARNING, null, ex); } return bounds; } /** * Finds out the monitor where the user currently has the input focus. * This method is usually used to help the client code to figure out on * which monitor it should place newly created windows/frames/dialogs. * * @return the GraphicsConfiguration of the monitor which currently has the * input focus */ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); } }