java Windows 任务栏高度/宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6844996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:33:44  来源:igfitidea点击:

Windows taskbar height/width

javataskbar

提问by mastaH

I can't figure out how to get the windows taskbar height dynamicaly to set my application fullscreen.
As you know, taskbar can be in four positions: bottom, top, left or right, so I'm wondering if it's possible to also know the current position to set the window bounds.

我不知道如何动态获取 Windows 任务栏高度以设置我的应用程序全屏。
如您所知,任务栏可以位于四个位置:底部、顶部、左侧或右侧,所以我想知道是否也可以知道当前位置来设置窗口边界。

EDIT: Using Lukas link I tryied this:

编辑:使用 Lukas 链接我尝试了这个:

GraphicsDevice myDevice;
Window myWindow;

try {
    myDevice.setFullScreenWindow(myWindow);
    ...
} finally {
    myDevice.setFullScreenWindow(null);
}

But I'm gettin a NullPointerException

但我开始了 NullPointerException

采纳答案by Hunter McMillen

When you create your JFrame. Make a call to the setExtendedState()method in the JFrame API

当你创建你的JFrame. 调用setExtendedState()JFrame API 中的方法

jFrame = new JFrame("TESTER");
jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

The MAXIMIZED_BOTH setting will set your window to fullscreen and automatically take into account the position of the Taskbar.

MAXIMIZED_BOTH 设置会将您的窗口设置为全屏并自动考虑任务栏的位置。

回答by necman

It is possible to obtain the Windows taskbar height if necessary:

如有必要,可以获取 Windows 任务栏高度:

Dimension scrnSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

int taskBarHeight = scrnSize.height - winSize.height;

回答by Lukas Knuth

If you want your Application to run in full-screen mode, you can enter it by getting a suitable GraphicsDeviceand using the setFullScreenWindow(Window)-method:

如果您希望您的应用程序以全屏模式运行,您可以通过获取合适的GraphicsDevice并使用setFullScreenWindow(Window)-method来输入它:

GraphicsDevice myDevice = GraphicsEnvironment.
   getLocalGraphicsEnvironment().getDefaultScreenDevice();
Window myWindow;

try {
    myDevice.setFullScreenWindow(myWindow);
    ...
} finally {
    myDevice.setFullScreenWindow(null);
}

For further (and more complete) information. see the Docs)

有关更多(和更完整)的信息。见文档

回答by nghiatm

You can use:

您可以使用:

int taskbarheight = Toolkit.getDefaultToolkit().getScreenSize().height 
    - GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height();

or you can use, as well:

或者你也可以使用:

JFrame frame = new JFrame();
frame.setSize(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getSize();

回答by HyperNeutrino

This is part of a program I wrote:

这是我写的程序的一部分:

public enum Location {
    TOP, RIGHT, BOTTOM, LEFT;
}

private static final class Taskbar {
    public final Location location;
    public final int width, height;

    private Taskbar(Location location, int width, int height) {
        this.location = location;
        this.width = width;
        this.height = height;
    }

    public static Taskbar getTaskbar() {
        Rectangle other = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getMaximumWindowBounds();
        return new Taskbar(other.x != 0 ? Location.TOP
                : (other.y != 0 ? Location.LEFT
                        : (other.width == IFrame.width ? Location.BOTTOM
                                : Location.RIGHT)), IFrame.width
                - other.width, IFrame.height - other.height);
    }
}

Essentially, calling Taskbar.getTaskbar()will give a taskbar containing information on its location (TOP, RIGHT, BOTTOM, LEFT), its width, and its height.

本质上,调用Taskbar.getTaskbar()将给出一个包含位置(TOPRIGHTBOTTOMLEFT)、宽度和高度信息的任务栏。