我能找到解決方案。基本上,您需要找到活動工作臺外殼(應用程序外殼),並在該外殼上使用以下方法,然後將實際所需的窗口推到前面。
您可以輕鬆修改此窗口,使您的窗口最大化,並在重畫之前添加方法shell.setMaximized(true)
。
private static void bringupDialog(WindowState state) {
final Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
//bring up the application to front
workbenchShell.setVisible(true);
workbenchShell.setMinimized(false);
workbenchShell.redraw();
//focus on dialog
workbenchShell.setActive();
workbenchShell.forceActive();
workbenchShell.setFocus();
workbenchShell.forceFocus();
workbenchShell.moveAbove(null);
workbenchShell.redraw();
Shell shell = instance.getShell(); // desired window shell
shell.setActive();
shell.forceActive();
shell.setFocus();
shell.forceFocus();
shell.moveAbove(null);
shell.redraw();
}
@ user2494817問題是關於SWT,不AWT/Swing的... – Baz 2014-10-31 20:06:54
@Baz權......這則:http://stackoverflow.com/questions/9722911/java-swt-application-bring- to-front :) – user2494817 2014-10-31 20:08:56
@ user2494817此解決方案專門針對Windows,問題針對Mac OS X專門 – 2014-11-03 14:57:17