Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SWT: How to indicate a menu item is selected

Tags:

java

menu

swt

Using SWT, what is the common way to indicate that a menu item (from a taskbar menu) is the currently active selection? Checkmark? Bold? How is this done with code?

like image 238
Dewayne Avatar asked Dec 18 '22 09:12

Dewayne


2 Answers

Use the CHECK style during instantiation:

MenuItem menuItem = new MenuItem(menu, SWT.CHECK);

Use getSelection to check status:

boolean isSelected = menuItem.getSelection();
like image 153
McDowell Avatar answered Dec 19 '22 23:12

McDowell


org.eclipse.swt.widgets.MenuItem setSelection(true) / getSelection()

The style of the selection depends on the style of the menu item: CHECK, CASCADE, PUSH, RADIO, SEPARATOR, as in:

alt text
(source: developpez.com)alt text
(source: developpez.com)

like image 34
VonC Avatar answered Dec 19 '22 23:12

VonC