[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: popup with checkboxes
|
(in case you haven't figured this out yet)
Creating an item with style SWT.CHECK does not display a checkbox beside the
item, but will display a checkmark beside it when it is in a checked state.
Your example snippet created a new Menu and MenuItem on every MenuDetect, so
there was no opportunity for an item to become checked and to show it on the
next MenuDetect. The following snippet shows checkmarks being used:
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem item = new MenuItem(menu, SWT.CHECK);
item.setText("Menu Item");
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
System.out.println("Item Selected");
}
});
shell.setMenu(menu);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"Simon Grey" <sgrey@xxxxxxxxx> wrote in message
news:a14ee45675795c289be027accd91a3e2$1@xxxxxxxxxxxxxxxxxx
> Thanks, Frank:
>
> I tried the following piece of code. It seems popup menu is displayed with
> one
> menu item called "Menu Item", but no checkbox is displayed. What do we
> need to make checkbox to display? Thanks,
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Listener;
> import org.eclipse.swt.widgets.Menu;
> import org.eclipse.swt.widgets.MenuItem;
> import org.eclipse.swt.widgets.Shell;
>
> public class PopupMenuTest
> {
> public static void main (String [] args) {
> final Display display = new Display ();
> final Shell shell = new Shell (display);
> shell.addListener (SWT.MenuDetect, new Listener () {
> public void handleEvent (Event event) {
> Menu menu = new Menu (shell, SWT.POP_UP);
> MenuItem item = new MenuItem (menu, SWT.CHECK);
> item.setText ("Menu Item");
> item.addListener (SWT.Selection, new Listener () {
> public void handleEvent (Event e) {
> System.out.println ("Item Selected");
> }
> });
> menu.setLocation (event.x, event.y);
> menu.setVisible (true);
> while (!menu.isDisposed () && menu.isVisible ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> menu.dispose ();
> }
> });
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> }
>