import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class PopupMenuMenuEvent {
public static void main(String[] args) {
Display display = new Display();
final Clipboard cb = new Clipboard(display);
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP);
Menu menu = new Menu(shell, SWT.POP_UP);
final MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
copyItem.setText("Copy");
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent e) {
System.out.println("Menu event");
}
});
text.setMenu(menu);
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
cb.dispose();
display.dispose();
}
}
|