Windows 任务栏高度/宽度

发布于 2024-11-26 11:54:52 字数 361 浏览 1 评论 0原文

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

编辑: 使用卢卡斯链接我尝试了这个:

GraphicsDevice myDevice;
Window myWindow;

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

但是我遇到了 NullPointerException

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.

EDIT:
Using Lukas link I tryied this:

GraphicsDevice myDevice;
Window myWindow;

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

But I'm gettin a NullPointerException

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

安稳善良 2024-12-03 11:54:52

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

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

int taskBarHeight = scrnSize.height - winSize.height;

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

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

int taskBarHeight = scrnSize.height - winSize.height;
多情癖 2024-12-03 11:54:52

当您创建 JFrame 时。调用 JFrame API 中的 setExtendedState() 方法

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

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

When you create your JFrame. Make a call to the setExtendedState() method in the 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.

云醉月微眠 2024-12-03 11:54:52

您可以使用:

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

或者您也可以使用:

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

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();
两仪 2024-12-03 11:54:52

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

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

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

获取更多(且更完整)的信息。请参阅文档

If you want your Application to run in full-screen mode, you can enter it by getting a suitable GraphicsDevice and using the 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)

浅唱ヾ落雨殇 2024-12-03 11:54:52

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

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);
    }
}

本质上,调用 Taskbar.getTaskbar() 将提供一个包含其位置信息的任务栏(TOPRIGHT、BOTTOMLEFT)、其宽度和高度。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文