Chapter 6. SWT Buttons

This chapter focuses on the SWT Button class. Button is part of the org.eclipse.swt.widgets package. Buttons are a standard part of any GUI and are used to perform a wide variety of tasks.

The most common button style is the push button, which enables the user to click the button to initiate some action. The Yes, No, and Cancel buttons that you often find on message boxes or other dialogs are examples of this button type, which you will sometimes see referred to as a command button .

Another button style is the radio button. A radio button is part of a group of buttons configured so that only one button within the group may be selected at any given time.

Yet a third frequently used button style is a checkbox. A checkbox is a button, or group of buttons, that permits the user to make multiple selections from within the group.

The final button style is the toggle button, which acts very similar to the check ToolItem type used in Chapter 4. In the examples that follow, you will work with each of these button types.

Creating Push-Style Buttons

The most common use of buttons in a GUI is to enable the user to click in order to initiate some action or process. For this purpose, you use the standard SWT.PUSH -style button, often referred to as a command button.

How do I do that?

Example 6-1 creates a window with a standard SWT.PUSH button.

Example 6-1. A standard push button

import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.*; ...

Get SWT: A Developer's Notebook 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.