Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » radio button group with no default selection
radio button group with no default selection [message #514872] Tue, 16 February 2010 23:34 Go to next message
luke w patterson is currently offline luke w pattersonFriend
Messages: 2
Registered: July 2009
Junior Member
didn't know until now about this user list, crossposting from dev list
------------------------------------------------------------ --------------

ok, I give up, hopefully someone can point me to a link and I'll be on my
way, what I want sounds simple enough, but I've been working on it with two
other team members for 4 hours now with no luck,

I want to create a reusable composite class that contains radio buttons and
I don't want any of them to be selected by default. It seems that when a
shell is activated that contains radio buttons, the first radio button on
the page gets selected. I found a partial answer here: ant-radio-buttons-not-initially-selected.html

that answer kinda works, but I don't want to mess up traversal, and I don't
want to add dummy buttons. Is it the OS that is selecting a default? or
SWT? How can I suppress that behavior or distinguish between OS noise and
actual user input?



swt 3.5, windows (i'm guessing part of the answer will involve the words
"windows 'feature'")
Re: radio button group with no default selection [message #514898 is a reply to message #514872] Wed, 17 February 2010 04:51 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
It is a pickle....

see this snippet

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class RadioButtons

    public RadioButtons()
        Display display = new Display();
        Shell shell = new Shell(display);

        shell.setLayout(new RowLayout());

        Label label = new Label(shell, SWT.NULL);
        label.setText("Gender: ");

        Button femaleButton = new Button(shell, SWT.RADIO);

        Button maleButton = new Button(shell, SWT.RADIO);
        // Button aleButton = new Button(shell, SWT.RADIO);
        // aleButton.setText("M");
        // Button leButton = new Button(shell, SWT.RADIO);
        // leButton.setText("M");

        label = new Label(shell, SWT.NULL);
        label.setText("  Title: ");

        Composite composite = new Composite(shell, SWT.None);
        composite.setLayout(new RowLayout());

        Button mrButton = new Button(composite, SWT.RADIO);

        Button mrsButton = new Button(composite, SWT.RADIO);
        Button msButton = new Button(composite, SWT.RADIO);

        label = new Label(composite, SWT.NULL);
        label.setText("Education: ");

        Composite composite1 = new Composite(composite, SWT.None);
        composite1.setLayout(new RowLayout());

        Button mrButton1 = new Button(composite1, SWT.RADIO);
        mrButton1.setText("High School");

        Button mrsButton1 = new Button(composite1, SWT.RADIO);
        Button msButton1 = new Button(composite1, SWT.RADIO);
        msButton1.setText("Post Graduate");
        // Button drButton = new Button(composite, SWT.RADIO);
        // drButton.setText("Dr.");

        // textUser.forceFocus();

        // Set up the event loop.
        while (!shell.isDisposed())
            if (!display.readAndDispatch())
                // If no more entries in event queue


    private void init()


    public static void main(String[] args)
        new RadioButtons();

radio buttons on shell
and on composite1 are not selected by default...

although if remove composite...
then default button enablement comes up...
Re: radio button group with no default selection [message #515045 is a reply to message #514898] Wed, 17 February 2010 14:50 Go to previous message
luke w patterson is currently offline luke w pattersonFriend
Messages: 2
Registered: July 2009
Junior Member
vijay wrote on Tue, 16 February 2010 23:51
It is a pickle....

see this snippet

Thanks Vijay

so it looks like the only workarounds involve tricking clippy?

it seems so strange that I can't offer a reusable composite containing radio choices which states that it can be enabled with nothing selected
Previous Topic:Sockets,Streams and Threads
Next Topic:Lockable Composite
Goto Forum:

Current Time: Tue May 30 09:16:44 GMT 2017

Powered by FUDForum. Page generated in 0.01854 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software