Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323664

Summary: MenuItem not added to menu
Product: [Eclipse Project] Platform Reporter: Scott Kovatch <skovatch>
Component: SWTAssignee: 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:

Description Scott Kovatch CLA 2010-08-25 18:19:49 EDT
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.
Comment 1 Scott Kovatch CLA 2010-08-25 19:14:49 EDT
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.