There is a way to make it work with what you initially tried. You actually needto call shell.setMinimized(false) and after that shell.setActive() torestore the previous state of the shell. However, that only works ifthe shell was truely in the minimized state. So here is my finalsolution, which artificially minimizes the shell if it was notminimized already. The cost is a quick animation if the minimization has to bedone.
shell.getDisplay().syncExec(newRunnable() {
@Override public void run() {
if (!shell.getMinimized())
{
shell.setMinimized(true);
}
shell.setMinimized(false);
shell.setActive();
}});
参考资料:http://stackoverflow.com/questions/2315560/how-do-you-force-a-java-swt-program-to-move-itself-to-the-foreground