Dewayne
Dewayne

Reputation: 3742

Java SWT: How to indicate a menu item is selected

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?

Upvotes: 4

Views: 7358

Answers (3)

VonC
VonC

Reputation: 1329942

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)

Upvotes: 4

McDowell
McDowell

Reputation: 108979

Use the CHECK style during instantiation:

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

Use getSelection to check status:

boolean isSelected = menuItem.getSelection();

Upvotes: 7

Kai Huppmann
Kai Huppmann

Reputation: 10775

MenuItem.getSelection()

Upvotes: 1

Related Questions