【问题标题】:Set/Get values for RadioGroupFieldEditor in SWT在 SWT 中设置/获取 RadioGroupFieldEditor 的值
【发布时间】:2012-08-25 07:32:36
【问题描述】:

我正在尝试在我正在开发的 Eclipse RCP 应用程序中添加 RadioGroupFieldEditor,但似乎无法做两件关键的事情:

  1. 设置单选按钮的值(即当对话框/窗口打开时,我想将默认设置为“button1”)
  2. 获取所选单选按钮的当前值(即用户选择了什么,或者如果没有设置,则为上面设置的默认值)。

我使用的代码如下:

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

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

我有一个 fireValueChanged() 方法,我可以用它来设置另一个 String 变量的值(当用户做出选择时),但这看起来很混乱。它也不允许我设置默认值...

我怀疑我遗漏了一些重要的东西!上面应该有get/set方法吗?

【问题讨论】:

    标签: java radio-button swt eclipse-rcp radio-group


    【解决方案1】:

    由于此控件在首选项上运行,因此您可以在首选项初始化程序中设置默认值。

    要获取控件的值,您可以通过 getRadioBoxControl(Composite) 方法 gt 实际的无线电控件并查询该对象。不是最干净的方法,但它确实可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2011-09-06
      相关资源
      最近更新 更多