0

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?

greg-449
  • 109,219
  • 232
  • 102
  • 145
altralaser
  • 2,035
  • 5
  • 36
  • 55

1 Answers1

0

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.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Ah ok. Unfortunately sometimes it's a little bit confusing to know where to search: In the JFace classes or in the wrapped SWT classes. – altralaser Feb 24 '16 at 20:15