| Summary: | MenuItem not added to menu | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Scott Kovatch <skovatch> |
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> |
| Status: | RESOLVED INVALID | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 3.6 | ||
| Target Milestone: | --- | ||
| Hardware: | Macintosh | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
Never mind. This call: Menu menu = new Menu(item); makes a DROP_DOWN menu but doesn't automatically add the Menu to the MenuItem. You need item.setItem(menu); to finish it up. |
Run this code: ========================= import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.*; public class MainMenu { public static void main(String[] args) { try { final Display display = new Display(); Shell s = new Shell(display); Menu bar = new Menu(s, SWT.BAR); MenuItem item = new MenuItem(bar, SWT.CASCADE); item.setText("File"); Menu menu = new Menu(bar); MenuItem exit = new MenuItem(menu, SWT.PUSH); exit.setText("Exit"); exit.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { display.dispose(); } }); s.setMenuBar(bar); s.open(); while (!display.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } catch (Throwable e) { e.printStackTrace(); } } } ================================== It should make a menu titled 'File' with one item "Exit", but you only see the menu and not the item.