Java - Screen Size on a Mac

风格不统一 提交于 2019-12-12 16:07:53

问题


I have a Java application, and in order to find the size of the screen to use, I do the following, for example:

Toolkit.getDefaultToolkit().getScreenSize().width;
Toolkit.getDefaultToolkit().getScreenSize().height;

In my application, I am painting some items on the screen. And to determine the position, I use these values for width and height (because I want a particular item at the very bottom).

But, I'm finding that it is going off the screen, even though it's position doesn't exceed what the value for the height of my screen is.

Then, I realized I'm on a Mac, and the window that pops up for the Java application starts below the little toolbar menu thing at the top of my Mac (you know, the thing that has the time, the battery, etc). Do I need to take the height of that bar into consideration in my application? If so, is there an easy way to say "if I'm on a mac, then subtract something from the height." Also, what is that value of the height of that Menu Bar?


回答1:


To get the maximum usable area, minus taskbars and menu bars, use the following:

Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

From the docs:

Returns the maximum bounds for centered Windows. These bounds account for objects in the native windowing system such as task bars and menu bars.



来源:https://stackoverflow.com/questions/7083410/java-screen-size-on-a-mac

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