Java SWT: how to specify a menu item

Using SWT, what is the general way to indicate that a menu item (from the taskbar menu) is the currently active selection? Check mark? Fatty? How is this done with code?

+3
source share
3 answers

Use the CHECK style during instance creation:

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

Use getSelection to check status:

boolean isSelected = menuItem.getSelection();
+5
source

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

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

alt text http://jmdoudoux.developpez.com/cours/developpons/java/images/swt047.png alt text http://jmdoudoux.developpez.com/cours/developpons/java/images/swt046.png

+3
MenuItem.getSelection()
0
source

Source: https://habr.com/ru/post/1704191/


All Articles