Add One Popup Menu to two different Controls : PopupMenu « SWT « Java Tutorial






Add One Popup Menu to two different Controls
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
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 PopupMenuAddTwoControls {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    
    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setSize(100, 100);
    
    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setBounds(100, 0, 100, 100);
    
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Popup");
    
    c1.setMenu(menu);
    c2.setMenu(menu);
    
    shell.setMenu(menu);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}








17.34.PopupMenu
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