Eclipse Search


Oct 18, 2010

New features on Mac

Windowless application:

       SWT now supports an application level menu, so now its possible for an app to have a MenuBar without any Shell

Here is the code sample:

package com.eclipse_tips.mac.sample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class WindowlessApp {

 private static int windowCount;

 public static void main(String[] args) {
  final Display display = new Display();

  Menu appMenuBar = display.getAppMenuBar();
  final MenuItem windowMenu = new MenuItem(appMenuBar, SWT.CASCADE);
  Menu windowSubMenu = new Menu(null, SWT.DROP_DOWN);
  createNWMenuItem(display, windowSubMenu);
  while (!display.isDisposed()) {
   if (!display.readAndDispatch())

 private static Shell createNewWindow(final Display display) {

  Shell shell = new Shell(display);
  Menu bar = new Menu(shell, SWT.BAR);
  shell.setText("Window #" + windowCount);

  MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
  fileItem.setText("&File" + windowCount);

  Menu submenu = new Menu(shell, SWT.DROP_DOWN);

  MenuItem item = new MenuItem(submenu, SWT.PUSH);
  item.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event e) {
    System.out.println("Select All");
  item.setText("Select All");
  createNWMenuItem(display, submenu);

  return shell;

 private static void createNWMenuItem(final Display display, Menu submenu) {
  MenuItem newWindowItem = new MenuItem(submenu, SWT.PUSH);
  newWindowItem.addListener(SWT.Selection, new Listener() {

   public void handleEvent(Event e) {
    Shell window = createNewWindow(display);
    window.setSize(300, 200);;
  newWindowItem.setText("New Window");


Native ToolBar:

     The native toolBar is now supported and it looks awesome. Here is the modified SWT ToolBar snippet in action:

SWT Native Toolbar on Mac

Window menu items:

    Eclipse adds support to the standard 'Minimize', 'Zoom' & 'Bring All to Front' menu items in the Window menu:

Mac standard menu items in Window menu

Proxy Icon:

     Eclipse now supports proxy icons in the window title. You can drag those icons to other apps or Cmd+click to directly navigate any folder in the file's hierarchy:
Proxy Icon in Eclipse Workbench

Note, these are available in the latest Nightly builds of 3.7 and are subjected to change before the release :-)


  1. Why Eclipse drawing (windows, menu, maximize ...) is very slow on Mac ? On windows in the same machine its OK.

  2. @Anonymous,
    There shouldn't be any performance issues. I'm using Eclipse on Mac for my regular development and didn't notice anything. Do you have any performance results tests to show that on Mac its slower?

  3. In the "windowless application" sample you have a while loop which runs as long as the display hasn't disposed. Why do you dispose it after the loop?

  4. This is awesome. I just googled your name because of the Eclipse article here , to see if I may find your e-mail address and ask you how to achieve a windowless global menu on the Mac. And what do I find? :-)

  5. Prakash, this is very cool indeed. Do you know if there is an easy/non-hackish way to get the native toolbar/coolbar L&F through RCP apps? I could try to grab the toolbar and muck with it, but I'm hoping there is an easier way?

  6. There isn't a easy way, except overriding WorkbenchWindowAdvisor.createWindowContents(). In that way, you can control the creation of the window elements. You can choose not to create the coolbar and then create the native tool bar there. Note that you need "lot" of work to add the perspective switcher in the tool bar - at least thats what I faced sometime back. After considering the effort, I abandoned the effort and focussed on other important features and fixes :-)