问题
With
Toolkit.getDefaultToolkit().getScreenSize()
I get the screen size.
But usually this isn't the available size I have for my own program, because on the mac there is a menubar on top and on the bottom an iconbar. Windows also has an iconbar. So how do I get the real available space?
回答1:
From Java forum:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = ge.getMaximumWindowBounds();
Now you have the bounds sans platform-dependent desktop decorations. I don't have a Mac around so I only verified that it works on WinXP/JDK6.
Note that if you auto-hide taskbar, the bounds do NOT include taskbar, which is correct.
回答2:
I'm not sure if this will work, but try the GraphicsConfiguration/GraphicsDevice instead. You might not be able to get a bounding box that discount the dock on OS X since the area of the dock is still considered screen space. I can move windows on top of it. I can also move the dock to be on the side and not at the bottom of the screen (same goes for the Windows task bar).
http://download.oracle.com/javase/6/docs/api/java/awt/GraphicsDevice.html
来源:https://stackoverflow.com/questions/3727589/how-do-i-get-the-real-usable-resolution