Determine height of screen in Java(在Java中确定屏幕高度)
问题描述
我的 JFrame 使用以下命令处于全屏模式:
I have my JFrame in full screen mode using the following:
setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);
我想知道高度.请注意, Toolkit.getDefaultToolkit().getScreenSize() 不起作用,因为我在 Mac 上,实际高度应不包括屏幕顶部 Mac 栏的高度.
And I want to know the height. Note that Toolkit.getDefaultToolkit().getScreenSize() does not work because I'm on a Mac and the real height should exclude the height of the Mac bar thing at the top of the screen.
以 Windows 为例,高度应不包括开始栏.因此,我想知道我拥有的窗口空间的真实高度.
And in the case of Windows, for example, the height should exclude the start bar. Hence, I want to know the true height of the window space I have.
推荐答案
我用这个
public static Rectangle getScreenViewableBounds() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
Rectangle bounds = new Rectangle(0, 0, 0, 0);
if (gd != null) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
bounds.x += insets.left;
bounds.y += insets.top;
bounds.width -= (insets.left + insets.right);
bounds.height -= (insets.top + insets.bottom);
}
return bounds;
}
确定安全"的屏幕边界.这会考虑到屏幕插入并产生一个安全"可视区域的矩形......
To determine the "safe" screen bounds. This takes into consideration the screen insets and produces a rectangle of a "safe" viewable area...
更新
经过一些测试,我很满意(就我有多个屏幕的 Windows 而言)GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()
似乎为默认监视器返回相同的结果.前面提到的方法的好处是,它可以用来确定任何设备的安全"边界
After a little testing, I'm satisifed (as far as I have Windows with multiple screens) that GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()
seems to return the same results for the default monitor. The benifit of the previous mention method, is it could be used to determine the "safe" bounds for any device
感谢 Java - Mac 上的屏幕大小
这篇关于在Java中确定屏幕高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在Java中确定屏幕高度


基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01