简体   繁体   English

Java - Mac 上的屏幕尺寸

[英]Java - Screen Size on a Mac

I have a Java application, and in order to find the size of the screen to use, I do the following, for example:我有一个 Java 应用程序,为了找到要使用的屏幕大小,我执行以下操作,例如:

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).为了确定 position,我使用这些值作为宽度和高度(因为我想要一个特定的项目在最底部)。

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.但是,我发现它正在离开屏幕,即使它的 position 没有超过我屏幕高度的值。

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).然后,我意识到我在 Mac 上,并且为 Java 应用程序弹出的 window 从我的 Mac 顶部的小工具栏菜单下方开始(你知道,有时间的东西,电池等) . 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."如果是这样,是否有一种简单的方法可以说“如果我在 Mac 上,则从高度中减去一些东西”。 Also, what is that value of the height of that Menu Bar?另外,那个菜单栏的高度值是多少?

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.返回居中 Windows 的最大边界。 These bounds account for objects in the native windowing system such as task bars and menu bars.这些边界考虑了本机窗口系统中的对象,例如任务栏和菜单栏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM