Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gerr

macrumors newbie
Original poster
Apr 30, 2008
1
0
I am developing an Eclipse plugin which, at some point, needs to display a regular Swing form. This regular Swing form has a menubar. Being on Mac OS I want the menubar to be shown in the global Mac menubar, so I set the "apple.laf.useScreenMenuBar" property to true. I am testing the plugin directly from Eclipse. While testing, I manage to get the form visible, but the menubar of the form is not displayed. Instead, the global Mac menubar becomes empty.

If I don't set the "apple.laf.useScreenMenuBar" property to true, then the menubar of the frame is displayed inside the frame, as expected. Also if I try to display the frame from a regular Java project (not a plugin project), then it works all fine and the menu is displayed correctly in the global Mac menubar.

The code which displays the frame is:

Code:
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

public class MyActionDelegate implements IWorkbenchWindowActionDelegate {

	MyFrameWithMenubar child;
	
	public void dispose() {
		child.dispose();
	}

	public void init(IWorkbenchWindow window) {
		System.out.println(System.getProperty("sun.boot.class.path"));
		System.setProperty("apple.laf.useScreenMenuBar", "true");
		child = new MyFrameWithMenubar();
		child.pack();
	}

	public void run(IAction action) {
		child.setVisible(true);
	}

	public void selectionChanged(IAction action, ISelection selection) {
	}

}

And the frame looks like this:

Code:
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MyFrameWithMenubar extends JFrame {
	
	private static final long serialVersionUID = 2644194413142912399L;

	public MyFrameWithMenubar()
	{
		super("Frame with menubar");
		
		JMenuBar mb = new JMenuBar();
		JMenu actions = mb.add(new JMenu("Actions"));
		actions.add(new JMenuItem("Do this"));
		actions.add(new JMenuItem("Do that"));
		JMenu help = mb.add(new JMenu("Help"));
		help.add(new JMenuItem("Show help"));
		setJMenuBar(mb);
		
		setPreferredSize(new Dimension(640, 480));
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
	}

}

Does anyone have any idea what may be causing this? Or some hint, or anything that could help in finding a solution?

Thanks,
Gabi.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.