Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350879

Summary: setSelection for radio button does not work
Product: [Eclipse Project] Platform Reporter: Keith Willenson <keith>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: major    
Priority: P3 CC: eclipse.felipe, remy.suen, shiluka
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Keith Willenson CLA 2011-06-30 15:32:49 EDT
Build Identifier: I20110613-1736

No matter which radio button has setSelection(true), the first button always is selected.

Reproducible: Always

Steps to Reproduce:
    int radiusRounding = 2;

    for (int i=0;i<=3;i++)
    {
      String value = "Button " + Integer.toString(i);
      Button b = new Button(entryComp, SWT.RADIO);
      b.setText(value);
      b.setSelection(i == radiusRounding);
    }
Comment 1 Felipe Heidrich CLA 2011-07-05 10:51:50 EDT
works for me:
public static void main(String[] args) {
	Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setLayout(new GridLayout());
	int radiusRounding = 2;
	for (int i = 0; i <= 3; i++) {
		String value = "Button " + Integer.toString(i);
		Button b = new Button(shell, SWT.RADIO);
		b.setText(value);
		b.setSelection(i == radiusRounding);
	}
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
	display.dispose();
}

can you please try this above?
I running SWT from head:
http://eclipse.org/swt/cvs.php
Comment 2 Shiluka Dharmasena CLA 2014-03-03 11:48:37 EST
it works on linux and windows

Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());

		Button b1 = new Button(shell, SWT.RADIO);
		b1.setText("button_1");

		Button b2 = new Button(shell, SWT.RADIO);
		b2.setText("button_2");

		Button b3 = new Button(shell, SWT.RADIO);
		b3.setText("button_3");

		b2.setSelection(true);

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
Comment 3 Shiluka Dharmasena CLA 2014-03-03 11:54:28 EST
it works on linux and windows

                Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());

		Button b1 = new Button(shell, SWT.RADIO);
		b1.setText("button_1");

		Button b2 = new Button(shell, SWT.RADIO);
		b2.setText("button_2");

		Button b3 = new Button(shell, SWT.RADIO);
		b3.setText("button_3");

		b2.setSelection(true);

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();


what is the OS you used ?
Comment 4 Eclipse Genie CLA 2020-03-26 18:35:16 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.