Chapter 8. SWT: Menus, Toolbars, Sliders, Trees, and Dialogs

SWT supports many more widgets than we had a chance to work with in the previous chapter, and we’ll get the details on a number of the most central SWT controls here: menus, toolbars, sliders, trees, and custom dialogs.

Working with Menus

As you’d expect, SWT supports menus, as any GUI builder should. The process of creating and supporting menus in your SWT applications is not necessarily easy, but it’s not unduly difficult. To make this work in an example, we’re going to create a menu system with a File menu and a Help menu and react to various menu selections, displaying text in a label to match the selected items.

To create a menu system in SWT, you create a Menu object, corresponding to the top level of the menu system. As with all the SWT controls, you can see the allowed styles back in Table 7-1; here are the possible styles for menus:

SWT.BAR

Sets menu bar behavior

SWT.DROP_DOWN

Creates a drop-down menu

SWT.POP_UP

Creates a pop-up menu

SWT.NO_RADIO_GROUP

Prevents the use of radio groups

SWT.LEFT_TO_RIGHT

Sets left-to-right orientation

SWT.RIGHT_TO_LEFT

Sets right-to-left orientation

The File and Help menus are MenuItem objects associated with the Menu object, and here are the possible styles for menu items:

SWT.CHECK

Creates a checkbox

SWT.CASCADE

Creates a cascading submenu

SWT.PUSH

Creates a push button

SWT.RADIO

Creates a radio button

SWT.SEPARATOR

Creates a menu separator

Tip

Note, in particular, how easy it is to add a menu ...

Get Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.