GraphicsEnvironment has a method which returns the maximum available size, accounting all taskbars etc. no matter where they are aligned:
GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()
Note: On multi-monitor systems, getMaximumWindowBounds()
returns the bounds of the entire display area. To get the usable bounds of a single display, use GraphicsConfiguration.getBounds()
and Toolkit.getScreenInsets()
as shown in other answers.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…