拥有JFrame而不调整任务栏更改 [英] To have a JFrame without adjusting for taskbar change

查看:49
本文介绍了拥有JFrame而不调整任务栏更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有一个JFrame,当我更改窗口任务栏的大小或位置时,该框架不应自行调整. 更改任务栏的大小和位置时,将完全调用JFrame的哪种方法?我将需要覆盖哪种方法?

I need to have a JFrame, which when i change the window taskbar size or position, the frame shouldn't adjust itself. Which method of the JFrame will be called exactly on changing the taskbar size and position? Which method will I be required to override?

说得更清楚些, 默认情况下,当我更改窗口任务栏的大小和位置时,JFrame实例将自行调整其高度和宽度.但是,当我扩展窗口任务栏或将任务栏从水平更改为垂直时,我的JFrame不会响应.它应该保持默认状态.

To put it in more clear words, By default the instance of JFrame will adjust its height and width by itself when I change the size and position of the window taskbar. But my JFrame shouldn't respond when I extend the window taskbar or when I change the taskbar from horizontal to vertical. It should remain in its default state.

推荐答案

我认为无法阻止它被移动.它似乎没有调用setBounds或setLocation或setSize,而是直接在OS级别上移动窗口.您可能要做的最好的事情就是使用ComponentListener检测边界变化,然后立即将窗口放回所需位置.

I don't think it's possible to prevent it from being moved. It doesn't seem to call setBounds or setLocation or setSize, but rather it moves the window directly at the OS level. The best you can probably do is detect bounds changes with a ComponentListener and then immediately put the window back to where you want it.

final Rectangle fixedPosition = new Rectangle(...);

frame.setBounds(fixedPosition);
frame.addComponentListener(new ComponentListener() {
    public void componentMoved(ComponentEvent e) {
        if (!frame.getBounds().equals(fixedPosition)) {
            frame.setBounds(fixedPosition);
        }
    }
    public void componentResized(ComponentEvent e) {
        componentMoved(e);
    }
    public void componentShown(ComponentEvent e) {}
    public void componentHidden(ComponentEvent e) {}
});

这篇关于拥有JFrame而不调整任务栏更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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