If I use com.apple.eawt.Application;
even minimally as instantiating it like this:
Application app = Application.getApplication ()
the default Mac application menu misbehaves.
The minimal runnable test code below shows, when it launches, a "Hello World" shell and only the default application menu, labelled 'SWT' as expected.
Without an Application, selecting 'Quit' (or pressing Command-Q keys) exits the program normally.
With an Application, selecting 'Quit' (or pressing Command-Q keys) appears to exit the program normally (for example shell disappears), but the menu labelled 'SWT' remains visible. It does not arm, nor is it selectable. According to the IDE (Idea), my test program is still running, and has to be terminated through the IDE.
In my environment, this is 100% reproducible with the test code below.
import com.apple.eawt.Application;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class AboutTester
{
public static void main ( String[] args )
{
Display display = new Display ();
Shell shell = new Shell ( display );
shell.setSize ( 300, 200 );
shell.setLayout ( new FillLayout () );
// Comment out the following line - problem goes away.
Application app = Application.getApplication ();
Label label = new Label ( shell, SWT.BORDER_SOLID );
label.setText ( "Hello World" );
shell.open ();
while ( !shell.isDisposed () )
{
if ( !display.readAndDispatch () )
display.sleep ();
}
display.dispose ();
}
}
Of course, not having access to a com.apple.eawt.Application;
is a biggish hindrance on a Mac.
Does anyone know of a solution to this problem?
Full disclosure: What I think may be happening (from other observations) is that Application is generating a menu, which SWT is then covering over with an SWT-generated menu. Attaching an AboutHandler() attaches to the Application-generated menu - and therefore appears to not work when the topmost SWT-generated menu is used. When the SWT-menu quits, it leaves the Application-generated menu behind as an orphan. My test app does not know how to clean this Application-generated menu, and therefore hangs. But that's speculation.
Mac OS X 10.6.8 (10K549)
org.eclipse.swt.cocoa.macosx.x86_64_3.7.0.v3735b.jar
org.eclipse.swt_3.7.1.v3738a.jar
(Ninja edit for typos)
I see the exact same issue, I think it may be a threading issue. If you want to have custom menus on mac, then look into using this file which handles that stuff from the Eclipse SWT side https://github.com/ajdaniel/tvrenamer/blob/devel/src/main/com/google/code/tvrenamer/view/CocoaUIEnhancer.java.