How do I get the real usable resolution

匆匆过客 提交于 2021-01-20 17:01:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!