eclipse - FieldEditorPreferencePage 中的布局问题

标签 eclipse eclipse-plugin swt eclipse-rcp jface

我在 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/

    相关文章:

    java - 如何以编程方式关闭 Eclipse 应用程序中的 View ?

    java - 如何在高分辨率屏幕上正确缩放图像

    java - 如何向 PatternFilter 中找到的文本添加粗体

    java - 尝试使用 cassandra 数据存储从 eclipse 运行 nutch 时出现 java.lang.NullPointerException

    java - 无法启动 Eclipse Kepler

    java - Eclipse 中的 "Add JARs"和 "Add External JARs"有什么区别?

    eclipse - 如何突出显示 Eclipse 的 Emacs 键绑定(bind)中的选择?

    android - Android SDK中的Eclipse Marketplace在哪里

    eclipse-plugin - 如何在 ShellEd 中禁用注释折叠

    java - 当我在swt中拖动对话框时如何防止检查按钮移动?