如何在 Eclipse 主详细信息块中将按钮放在另一个按钮下方?
How to place button below another in Eclipse Master Details Block?
我目前有以下Master Details Block。问题是我想将 Button2
直接放在 Button1
.
下面
我修改了这个 tutorial 的代码。
这是我的代码:
protected void createMasterPart(final IManagedForm managedForm,
Composite parent) {
FormToolkit toolkit = managedForm.getToolkit();
Section section = toolkit.createSection(parent, Section.DESCRIPTION|Section.TITLE_BAR);
section.setText("Test"); //$NON-NLS-1$
section.setDescription("Test"); //$NON-NLS-1$
section.marginWidth = 10;
section.marginHeight = 5;
Composite client = toolkit.createComposite(section, SWT.WRAP);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 2;
layout.marginHeight = 2;
client.setLayout(layout);
Table t = toolkit.createTable(client, SWT.NULL);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 20;
gd.widthHint = 100;
t.setLayoutData(gd);
toolkit.paintBordersFor(client);
Button button1 = toolkit.createButton(client, "Button 1", SWT.PUSH); //$NON-NLS-1$
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button1.setLayoutData(gd);
Button button2 = toolkit.createButton(client, "Button 2", SWT.PUSH); //$NON-NLS-1$
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button2.setLayoutData(gd);
section.setClient(client);
final SectionPart spart = new SectionPart(section);
managedForm.addPart(spart);
TableViewer viewer = new TableViewer(t);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
managedForm.fireSelectionChanged(spart, event.getSelection());
}
});
viewer.setContentProvider(new MasterContentProvider());
viewer.setLabelProvider(new MasterLabelProvider());
viewer.setInput(page.getEditor().getEditorInput());
}
如何做到这一点?
由于您有两列,布局当前将 Table 放在左列的第一行,然后将第一个按钮放在右列。第二个按钮位于新行的左列中。
要让按钮进入右栏,您需要创建一个额外的 Composite
来容纳两个(或更多)按钮:
Composite buttComposite = toolkit.createComposite(client, SWT.NONE);
buttComposite.setLayout(new GridLayout());
buttComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false));
Button button1 = toolkit.createButton(buttComposite, "Button 1", SWT.PUSH);
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button1.setLayoutData(gd);
Button button2 = toolkit.createButton(buttComposite, "Button 2", SWT.PUSH);
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button2.setLayoutData(gd);
我目前有以下Master Details Block。问题是我想将 Button2
直接放在 Button1
.
我修改了这个 tutorial 的代码。
这是我的代码:
protected void createMasterPart(final IManagedForm managedForm,
Composite parent) {
FormToolkit toolkit = managedForm.getToolkit();
Section section = toolkit.createSection(parent, Section.DESCRIPTION|Section.TITLE_BAR);
section.setText("Test"); //$NON-NLS-1$
section.setDescription("Test"); //$NON-NLS-1$
section.marginWidth = 10;
section.marginHeight = 5;
Composite client = toolkit.createComposite(section, SWT.WRAP);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 2;
layout.marginHeight = 2;
client.setLayout(layout);
Table t = toolkit.createTable(client, SWT.NULL);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 20;
gd.widthHint = 100;
t.setLayoutData(gd);
toolkit.paintBordersFor(client);
Button button1 = toolkit.createButton(client, "Button 1", SWT.PUSH); //$NON-NLS-1$
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button1.setLayoutData(gd);
Button button2 = toolkit.createButton(client, "Button 2", SWT.PUSH); //$NON-NLS-1$
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button2.setLayoutData(gd);
section.setClient(client);
final SectionPart spart = new SectionPart(section);
managedForm.addPart(spart);
TableViewer viewer = new TableViewer(t);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
managedForm.fireSelectionChanged(spart, event.getSelection());
}
});
viewer.setContentProvider(new MasterContentProvider());
viewer.setLabelProvider(new MasterLabelProvider());
viewer.setInput(page.getEditor().getEditorInput());
}
如何做到这一点?
由于您有两列,布局当前将 Table 放在左列的第一行,然后将第一个按钮放在右列。第二个按钮位于新行的左列中。
要让按钮进入右栏,您需要创建一个额外的 Composite
来容纳两个(或更多)按钮:
Composite buttComposite = toolkit.createComposite(client, SWT.NONE);
buttComposite.setLayout(new GridLayout());
buttComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, false));
Button button1 = toolkit.createButton(buttComposite, "Button 1", SWT.PUSH);
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button1.setLayoutData(gd);
Button button2 = toolkit.createButton(buttComposite, "Button 2", SWT.PUSH);
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
button2.setLayoutData(gd);