且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确定屏幕在Java中的高度

更新时间:2023-11-14 12:58:28

我用这个

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