Java SWT应用程序 - 带到前面 [英] Java SWT application - Bring To Front

查看:350
本文介绍了Java SWT应用程序 - 带到前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Windows 7上开发一个SWT java应用程序。通常应用程序将被最小化,并且当串行端口上有事件时,应用程序应该最大化自身。以下代码执行最大化部分。

I am currently developing an SWT java application on Windows 7. Usually the application will be minimized, and when there is an event on the serial port the application should maximizes itself. The following code does the maximization part.

private void bringToFront(final Shell shell) {
    shell.getDisplay().asyncExec(new Runnable() {
        public void run() {
            if(!shell.getMaximized()){
                shell.setMaximized(true);
            }
            shell.forceActive();
        }
    });
}

但有时SWT应用程序在另一个应用程序后最大化。例如,如果我在全屏模式下运行powerpoint,则最大化应用程序落后于powerpoint演示。我想最大限度地把它带到所有其他应用程序前面。

But sometimes the SWT application is maximized behind another application. For example, if I have a powerpoint running in Fullscreen mode maximized application is behind powerpoint presentation. I would like to get it maximized and bring in front of all other applications.

任何人都可以帮助我吗?

Can anyone help me?

推荐答案

除此之外,还有另一种hackey方式可以做到这一点,这并不需要你最小化其他一切。你实际上需要调用 shell.setMinimized(false)然后再调用 shell.setActive()来恢复以前的状态的 shell 。但是,只有在 shell 真正处于最小化状态时才有效。所以这是我的最终解决方案,如果它没有被最小化,人为地最小化 shell 。如果必须进行最小化,则成本是一个快速动画。

There is a another "hackey" way to do this than what you found, which does not require you to minimize everything else. You actually need to call shell.setMinimized(false) and after that shell.setActive() to restore the previous state of the shell. However, that only works if the shell was truely in the minimized state. So here is my final solution, which artificially minimizes the shell if it was not minimized already. The cost is a quick animation if the minimization has to be done.

shell.getDisplay().syncExec(new Runnable() {

    @Override
    public void run() {
        if (!shell.getMinimized())
        {
            shell.setMinimized(true);
        }
        shell.setMinimized(false);
        shell.setActive();
    }
});

这篇关于Java SWT应用程序 - 带到前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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