Popup Radio MenuItem : PopupMenu « SWT « Java Tutorial

Popup Radio MenuItem
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class MenuItemPopupRadio {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Menu menu = new Menu(shell, SWT.POP_UP);
    for (int i = 0; i < 4; i++) {
      MenuItem item = new MenuItem(menu, SWT.RADIO);
      item.setText("Item " + i);
      item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
          MenuItem item = (MenuItem) e.widget;
          if (item.getSelection()) {
            System.out.println(item + " selected");
          } else {
            System.out.println(item + " unselected");
    shell.setSize(300, 300);
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())

17.34.1.Creating a Popup MenuCreating a Popup Menu
17.34.2.Show a popup menu (wait for it to close)Show a popup menu (wait for it to close)
17.34.3.Popup Radio MenuItemPopup Radio MenuItem
17.34.4.Add One Popup Menu to two different ControlsAdd One Popup Menu to two different Controls
17.34.5.PopupMenu is disposed with the compositePopupMenu is disposed with the composite
17.34.6.PopupMenu is not disposed with the compositePopupMenu is not disposed with the composite