我有一个JFace应用程序,我正在使用Tray类和弹出菜单:
public class MyApp extends ApplicationWindow {
private TrayItem trayItem;
private Menu trayMenu;
private MenuItem trayOpenMenu;
@Override
protected Control createContents(Composite parent) {
Tray tray = Display.getCurrent().getSystemTray();
trayItem = new TrayItem(tray, SWT.NONE);
trayItem.setToolTipText(Constants.APP_NAME);
trayItem.setVisible(false);
trayItem.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
trayMenu.setVisible(true);
}
});
trayMenu = new Menu(getShell(), SWT.POP_UP);
trayOpenMenu = new MenuItem(trayMenu, SWT.PUSH);
trayOpenMenu.setText("&Open");
}
}
每次窗口最小化时,我都会显示托盘项目:
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.addListener(SWT.Iconify, new Listener() {
@Override
public void handleEvent(Event e) {
trayItem.setVisible(true);
}
});
newShell.addListener(SWT.Deiconify, new Listener() {
@Override
public void handleEvent(Event e) {
trayItem.setVisible(false);
}
});
}
但我不知道如何通过点击打开的菜单将窗口重新放到前面(调整大小)?
答案 0 :(得分:0)
使用Shell
参数调用setMinimized
false
方法:
shell.setMinimized(false);
您可能还想使用
shell.setActive();
shell.moveAbove(null);
使shell处于活动状态并高于其他窗口。