java - 更改 RadioGroupFieldEditor 的值

标签 java swt

Possible Duplicate:
Set/Get values for RadioGroupFieldEditor in SWT

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

最佳答案

您可以通过迭代 RadioGroupFieldEditor 的子项来设置对各个 Button 的选择。这有点老套,但我没有看到更简单的方法:

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/

相关文章:

java - 使用Java序列化来保存对象

java - 无法解析符号 ITelephony

java - SCJP-- 考试问题

java - 如何在富客户端平台中为自定义语言编写源代码编辑器?

java - SWT 文件对话框 : Selecting directories instead of files

eclipse - "paste"SWT 小部件上的监听器

Java如何调用kotlin扩展方法

java - Spring 数据 JPA + openjpa : Is it possible to join a table not in OR-Hierarchy?

java - SWT 选项卡文件夹 : How do you automatically compress TabItems when there are too many

java - 如何使用swt向表中添加一行