Hiding the Window in RAP Applications

November 12, 2007 | 2 min Read

One of the frequently asked questions while showing RAP is “how can I hide the window”? Personally, I also find the window-in-a-window metaphor (shown above) somewhat confusing and unusual for a browser based application. Fortunately it is really easy to take care of that by configuring the Shell widget associated with that window, as explained in the rest of the article.

Maximized Window with No Title

To get the result shown above we need to apply the following changes to our WorkbenchWindowAdvisor implementation:

  1. we use the style-bit SWT.NO_TRIM before creating the Shell. This will remove the title-bar, the minimize/maximize/close buttons and the ability for manually resizing the window.

  2. we overwrite the WorkbenchWindowAdvisor.postWindowCreate() method. Here we set the state of the Shell to maximized.

  3. optional: depending on the requirements and complexity of our application it may be desirable to hide the menu bar by calling getWindowConfigurer().setShowMenuBar( false ). This is usually a good choice for small applications where the menu bar may not be needed. ```java public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {   // …

      public void preWindowOpen() {     // …     getWindowConfigurer().setShellStyle( SWT.NO_TRIM );     getWindowConfigurer().setShowMenuBar( false );   }

      public void postWindowCreate() {     Shell shell = getWindowConfigurer().getWindow().getShell();     shell.setMaximized( true );   } } ```

Maximized Window with Plain Title

This is a slight variation of the previous example. We have kept the window maximized but added a title bar. Note that the title bar is missing the usual minimize / maximize / close buttons which do not make much sense in a browser-based application that has only a single workbench window. To get the result shown we used SWT.TITLE style-bit instead of SWT.NO_TRIM:

java   public void preWindowOpen() {     // ...     getWindowConfigurer().setShellStyle( SWT.TITLE );   }

Note that is it possible to customize the font and colors in the title bar using the RAP Theming extension point (org.eclipse.rap.ui.themes). So if you don’t like the blue background you can change it. Theming will be a topic in a future blog post.