在SWT中设置/获取RadioGroupFieldEditor的值 [英] Set/Get values for RadioGroupFieldEditor in SWT

查看:151
本文介绍了在SWT中设置/获取RadioGroupFieldEditor的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to add a RadioGroupFieldEditor in an Eclipse RCP application I'm developing, but seem unable to do two key things:


  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变量(当用户做出选择时),但是这看起来很乱。它也不允许我设置默认值...

I have a fireValueChanged() method, which I could use to set another String variable with the value (when the user makes a choice), but this just seems messy. It also won't allow me to set the default value...

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

I suspect I'm missing something significant! Should there be get/set methods for the above?

推荐答案

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

Since this control is operating on preferences, you can set the default value in your preference initializer.

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

To get the value of the control, you could gt the actual radio control via the getRadioBoxControl(Composite) method and query that object. Not the cleanest way, but it does work adequately.

这篇关于在SWT中设置/获取RadioGroupFieldEditor的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆