Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323664 - MenuItem not added to menu
Summary: MenuItem not added to menu
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-25 18:19 EDT by Scott Kovatch CLA
Modified: 2010-08-25 19:14 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.