Determining CHECK Button Status
Proper interface design sometimes requires you to programmatically interact with the state of a button. An example is when you need to set a button’s state to checked, depending upon a value retrieved from a database or upon the occurrence of some other condition in the application
How do I do that?
The properties of Button
are accessible using
get
and set methods in the
JavaBeans paradigm. To programmatically cause a button to be checked,
use this code:
Note
Pass false to setSelection( ) to uncheck the button.
b1.setSelection(true);
Use getSelection( )
to determine the current state
of a variable:
boolean selected = b1.getSelection( );
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.