Search code examples
javaswtjfacetray

Resize JFace application window after minimizing


I have a JFace application and I'm using a Tray class and a popup menu:

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

Everytime the window is minimized I show the tray item:

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

But I don't know how to bring the window back to the front (resize it) by clicking the open menu?


Solution

  • Call the Shell setMinimized method with a false argument:

    shell.setMinimized(false);
    

    You may also want to use

    shell.setActive();
    shell.moveAbove(null);
    

    to make the shell active and above other windows.