简体   繁体   English

如何在扩展FieldEditorPreferencePage的首选项页中添加按钮

[英]How can I add Buttons in Preference Page which extends FieldEditorPreferencePage

I have one Preference Page which extending FieldEditorPreferencePage .I want align two SWT buttons just before Restore Defaults & Apply buttons as shown in the image. 我有一个首选项页面,该FieldEditorPreferencePage扩展了FieldEditorPreferencePage 。我想在Restore DefaultsApply按钮之前对齐两个SWT按钮,如图所示。

在此处输入图片说明

How can I do this? 我怎样才能做到这一点?

When you look at the structure of the UI, you'll see that the preference page building code creates a container and then gives you this container to fill. 当您查看UI的结构时,您会看到首选项页面构建代码创建了一个容器,然后为您提供了要填充的容器。

The container is a sibling of the container which contains the buttons "Restore Defaults" and "Apply" in the image. 该容器是该容器的兄弟,其中包含图像中的“还原默认值”和“应用”按钮。 Since it's a sibling (ie the buttons and your buttons are not in the same container), you can't align your buttons to them (layout only works in the same container). 由于它是同级的(即按钮和按钮不在同一容器中),因此无法将按钮与它们对齐(布局仅在同一容器中起作用)。

Now the simple solution would be to go to your parent and then search for the sibling container to add your buttons. 现在,简单的解决方案是转到您的父母,然后搜索同级容器以添加您的按钮。 But that would make the buttons stick around when the user leaves your preferences page. 但这会使按钮在用户离开您的首选项页面时停留。 And if you're not careful, the user would get two more buttons each time he visits your page. 而且,如果您不小心,则用户每次访问您的页面时,都会获得另外两个按钮。

The alternative is to use a grid layout and add a container below your editors which spans all columns. 替代方法是使用网格布局,并在编辑器下方添加一个跨越所有列的容器。 Use a Composite for this. 为此使用Composite Configure this container to grow in both directions. 将此容器配置为双向增长。

Assign a new grid layout to the inner container I1. 为内部容器I1分配一个新的网格布局。 Inside the container, add another container I2 which doesn't grow. 在容器内,添加另一个不会增长的容器I2。 Position it right/bottom. 将其放置在正确的位置/底部。

Add your buttons to I2. 将按钮添加到I2。

Ie you have page contains I1 contains I2 contains buttons. 即您有页面包含I1包含I2包含按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM