I've got a custom Dialog which contains two SWT.RADIO buttons and one SWT.PUSH button (opens a FileDialog). After I clicked the the second SWT.RADIO Button, clicked the SWT.PUSH button and returned from the FileDialog, the SWT.RADIO buttons are reset to their default selection.
How can I prevent that?
Reproducable code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
public class TestDialog {
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(30, 30, 300, 150);
shell.setLayout(new GridLayout(1, false));
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new GridLayout(2, false));
Button btnRadio1 = new Button(comp, SWT.RADIO);
btnRadio1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
btnRadio1.setText("Radio Button 1");
Button btnRadio2 = new Button(comp, SWT.RADIO);
btnRadio2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
btnRadio2.setText("Radio Button 2");
Composite comp2 = new Composite(shell, SWT.NO_RADIO_GROUP);
comp2.setLayout(new GridLayout(1, false));
Button btnPush = new Button(comp2, SWT.NONE);
btnPush.setText("Push Button");
btnPush.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
FileDialog dirDialog = new FileDialog(shell);
dirDialog.open();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}