确定屏幕在Java中的高度 [英] Determine height of screen in Java

查看:316
本文介绍了确定屏幕在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...

更新

一个小测试后,我satisifed(据我的Windows有多个屏幕)的 GraphicsEnvironment.getLocalGraphicsEnvironment()。getMaximumWindowBounds()好像又回到了默认显示器相同的结果。的previous提及方法的benifit,是它可用于确定任何器件中的安全范围

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

感谢爪哇 - 屏幕尺寸在Mac

这篇关于确定屏幕在Java中的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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