I would like to get the effective screen size. That is: the size of the screen without the taskbar (or the equivalent on Linux/Mac).
I am currently using...
component.getGraphicsConfiguration().getBounds()
...and subtracting the default taskbar size depending on the OS, but I would like a way that works even if the user has resized/moved the taskbar.
The following Java code demonstrates how to get the screen size, using the Java Toolkit class: // java - get screen size using the Toolkit class Dimension screenSize = Toolkit. getDefaultToolkit(). getScreenSize();
Select all components of JFrame, right click, select 'Auto Resizing', check for both Horizontal and Vertical, close . Show activity on this post. Calling pack() will usually result in the window being resized to fit the contents' preferred size.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With