Possible Duplicate:
Set/Get values for RadioGroupFieldEditor in SWT




我有一个RadioGroupFieldEditor字段和一个浏览器,用于在应用程序中选择数据类型,用户可以选择单选按钮作为数据类型,也可以使用浏览按钮选择新的数据类型。
如果用户选择一个单选按钮,然后单击浏览按钮,我想删除RadioGroupFieldEditor的选择。我怎样才能做到这一点

最佳答案

您可以通过遍历Button的子级来设置各个RadioGroupFieldEditor的选择。这有点骇人听闻,但我看不到更简单的方法:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    String[][] radioButtonOptions = new String[][] { { "Button1", "button1" }, { "Button2", "button2" } };

    final RadioGroupFieldEditor radioButtonGroup = new RadioGroupFieldEditor("PrefValue", "Choose Button1 or Button2", 2, radioButtonOptions, shell, true);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Deselect");

    button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            Composite temp = radioButtonGroup.getRadioBoxControl(shell);
            Control[] children = temp.getChildren();

            for(Control child : children)
            {
                if(child instanceof Button)
                {
                    ((Button)child).setSelection(false);
                }
            }
        }
    });


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

关于java - 更改RadioGroupFieldEditor的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12471473/

10-09 05:02