Java SWT application - Bring To Front

前端 未结 4 1232
深忆病人
深忆病人 2021-02-15 03:23

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 m

4条回答
  •  忘了有多久
    2021-02-15 03:52

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

提交回复
热议问题