我在 FieldEditorPreferencePage 中的布局设置有以下问题。
我的代码是这样的:
public void createFieldEditors () {
Group pv = new group(getfieldEditorParent(), SWT.SHADOW_OUT);
Group of = new group(getfieldEditorParent(), SWT.SHADOW_OUT);
pv.setText(“pv”);
of.setText(“of”);
GridLayout layout = new GridLayout(2,false);
pv.setLayout(layout);
of.setLayout(layout);
addField(new StringFieldEditor(“PreferenceStore name”,“Text:”, pv);
addField(new StringFieldEditor(“PreferenceStore name”,“Text:”, pv);
addField(new StringFieldEditor(“PreferenceStore name”,“Text:”, of);
addField(new StringFieldEditor(“PreferenceStore name”,“Text:”, of);
and so on.
}
问题是它不适用于 GridLayout。
StringFieldEditor 不是并行的。列数始终为 1。此外,当我尝试更改组中 StringFieldEditors 的大小时,它也不起作用。
有人有任何想法吗?
谢谢。
最佳答案
问题是当您使用 FieldEditorPreferencePage
时,您只能使用 FieldEditor
子类作为组件。这是文档中的一个片段:
FieldEditorPreferencePage implements a page that uses these field editors to display and store the preference values on the page. Instead of creating SWT controls to fill its contents, a FieldEditorPreferencePage subclass creates field editors to display the contents. All of the fields on the page must be implemented as field editors.
这意味着你有两种选择来实现你想要的:
FieldEditor
子类,这将代表组小部件。 FieldEditorPreferencePage
,但只有一个 PreferencePage
反而。那么你必须实现createContents
方法而不是 createFieldEditors
.您还必须管理属性的加载和保存。 如果你想提供一些复杂的布局,我认为第二种方法可能更容易。您可能会发现更多信息 here
关于eclipse - FieldEditorPreferencePage 中的布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/490015/