简体   繁体   English

SWT:在运行时更改 Shell 的样式

[英]SWT: Change style of a Shell at runtime

Is there a way to change the style of a Shell at runtime?有没有办法在运行时更改 Shell 的样式?

I would like to have a shell not resizable but capable to fill, with its content, the whole screen, when it's in fullscreen.我想要一个不能调整大小但能够在全屏时用其内容填充整个屏幕的外壳。 Is there a way to accomplish that?有没有办法做到这一点?

In other words, when a Shell is not resizable and it has for example a Background Image I get this in full screen :换句话说,当外壳不可调整大小并且它具有例如背景图像时,我会在全屏显示: 在此处输入图片说明

On the other hand when the Shell is resizable and I go in full screen I get this:另一方面,当 Shell 可调整大小并全屏显示时,我会得到以下信息: 在此处输入图片说明

So would like to obtain the second effect but with a not resizable Shell.所以想获得第二种效果,但不能调整大小的外壳。

Any help would be appreciated.任何帮助,将不胜感激。

Following Stefan's comment, I was able to do it listening to the resize event and checking the fullscreen flag, resizing appropriately the shell's size to the monitor size when it's in full screen and to normal size when is not.按照 Stefan 的评论,我能够监听 resize 事件并检查全屏标志,将外壳的大小适当地调整为全屏时的显示器大小,而不是正常大小时。 Here the code that does the trick:这是可以解决问题的代码:

shell.addListener(SWT.Resize, new Listener() {
            @Override
            public void handleEvent(Event arg0) {
                if (shell.getFullScreen()) {
                    Rectangle r = getMonitorSize(shell);
                    shell.setSize(r.width, r.height);
                    shell.redraw();
                } else {
                    shell.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
                    shell.redraw();
                }
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM