Causing No Radio Button to be Selected

In a group of Radio buttons, one button must be selected at all times. In Figure 6-3, when the window opens, Check Me is checked by default. Yet, proper functioning of your user interface may require that a window open with no button currently selected.

How do I do that?

To cause a group of buttons to have no default option, simply create a hidden button and set its selection property to true:

final Button fake = new Button(s, SWT.RADIO);
fake.setSelection(true);

Do not make the fake button visible, to preserve the group you wish the user to see on-screen.

Warning

Interestingly, on Windows XP, explicitly making the fake button invisible causes it not to count as part of the group.

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.