Enabling and Disabling Buttons
It is often useful to “disable” a button when it is not appropriate for the user to initiate the action to be taken upon a button click, or when the option represented by a check or radio button is not available. In fact, users expect this behavior. It is disconcerting for the user to click an enabled button, only to have no action take place. To prevent discomforting your users, you must enable and disable buttons depending upon program conditions.
How do I do that?
A button is disabled by:
b1.setEnabled(false);
Conversely, a button is enabled by:
b1.setEnabled(false);
Figure 6-8 shows the effect of disabling an
SWT.PUSH
-style button:
Figure 6-8. Disabled push button
The techniques discussed in this chapter are useful when creating and
working with Button
widgets, which form a central
part of many user interfaces.
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.