radio button group with no default selection [message #514872] |
Tue, 16 February 2010 23:34 |
luke w patterson Messages: 2 Registered: July 2009 |
Junior Member |
|
|
didn't know until now about this user list, crossposting from dev list
http://dev.eclipse.org/mhonarc/lists/platform-swt-dev/
------------------------------------------------------------ --------------
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:
http://www.rhinocerus.net/forum/lang-java-gui/590377-swt-i-w 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?
Thanks,
Luke
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 |
Vijay Raj 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: ");
label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
Button femaleButton = new Button(shell, SWT.RADIO);
femaleButton.setText("F");
Button maleButton = new Button(shell, SWT.RADIO);
maleButton.setText("M");
// 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: ");
label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
Composite composite = new Composite(shell, SWT.None);
composite.setLayout(new RowLayout());
Button mrButton = new Button(composite, SWT.RADIO);
mrButton.setText("Mr.");
Button mrsButton = new Button(composite, SWT.RADIO);
mrsButton.setText("Mrs.");
Button msButton = new Button(composite, SWT.RADIO);
msButton.setText("Ms.");
label = new Label(composite, SWT.NULL);
label.setText("Education: ");
label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
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);
mrsButton1.setText("Graduate");
Button msButton1 = new Button(composite1, SWT.RADIO);
msButton1.setText("Post Graduate");
// Button drButton = new Button(composite, SWT.RADIO);
// drButton.setText("Dr.");
shell.pack();
shell.open();
// textUser.forceFocus();
// Set up the event loop.
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
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...
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
|
Powered by
FUDForum. Page generated in 0.03691 seconds