1

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();
    }
}
3
  • Ahh sorry, I should have done that. Updated the question now.
    – Dominik
    Feb 6, 2020 at 19:34
  • The problem seems to be the FileDialog call. If I open up a MessageDialog.openinformation(), the RADIO buttons do not reset.
    – Dominik
    Feb 6, 2020 at 21:15
  • This looks like a focus-related bug, I've reported it at bugs.eclipse.org/bugs/show_bug.cgi?id=559920 Feb 7, 2020 at 13:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.