【问题标题】:Changing the value for RadioGroupFieldEditor [duplicate]更改 RadioGroupFieldEditor 的值 [重复]
【发布时间】:2012-09-18 06:28:36
【问题描述】:

可能重复:
Set/Get values for RadioGroupFieldEditor in SWT

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

【问题讨论】:

  • 怎么样 btnYourRadioBottn.setSelection(False);在您浏览按钮的小部件选择事件中
  • @Dinup: rdiogroupfieldeditor 没有 setSelection()
  • @BAZ:我已经看过了。我不想设置或获取 vlue。我想删除选择

标签: java swt


【解决方案1】:

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

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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2020-09-01
    • 2021-05-27
    • 2021-10-17
    • 2015-02-07
    相关资源
    最近更新 更多