Java-Mac上的屏幕尺寸 [英] Java - Screen Size on a Mac

查看:168
本文介绍了Java-Mac上的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序,并且为了找到要使用的屏幕大小,我执行以下操作,例如:

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.

然后,我意识到我在Mac上,为Java应用程序弹出的窗口从Mac顶部的工具栏菜单小菜单下面开始(您知道,那是有时间的,还有电池, ETC).在我的应用程序中是否需要考虑该钢筋的高度?如果是这样,是否有一种简单的方法说如果我使用的是Mac,则从高处减去一些东西".另外,该菜单栏的高度值是什么?

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?

推荐答案

要获得最大可用区域,减去任务栏和菜单栏,请使用以下命令:

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

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

docs :

返回居中Windows的最大边界.这些界限帐户 适用于本机窗口系统中的对象,例如任务栏和菜单 酒吧.

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

这篇关于Java-Mac上的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆