gpt4 book ai didi

java - 两个 Eclipse UI Form 部分捕获多余的垂直空间并正确折叠?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:18:22 25 4
gpt4 key购买 nike

我正在尝试创建一个具有三个可折叠部分的 Eclipse Form,一个固定大小,另外两个应该捕获编辑器窗口中所有剩余的垂直空间,这样,当其中一个底部部分折叠时,另一个一个将填满所有可用空间。

我已阅读forms article ,尝试了 grabExcessVerticalSpaceSWT.FILL 的多种变体以及这些部分的 GridData 必须提供的几乎所有内容,但没有成功。我还尝试将客户端部分嵌套在 grabExcess...Space 的复合 Material 中,但这也无济于事。调用 layout() 没有帮助,折叠部分时表单重排,折叠第一部分工作正常。

这是一个包含三个部分的表单的代码,但其中两个底部部分在折叠时只放弃了一小部分空间,而不是我想要的全部:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.SectionPart;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class SectionFormPage extends FormPage {
private IManagedForm managedForm;

public SectionFormPage(FormEditor editor) {
super(editor, "sectionEditor", "title");
}

protected void createFormContent(IManagedForm managedForm) {
this.managedForm = managedForm;
FormToolkit toolkit = managedForm.getToolkit();
Composite body = managedForm.getForm().getBody();

body.setLayout(new GridLayout());

createSectionWithButton(toolkit, body, new GridData(SWT.FILL, SWT.FILL, true, false));
createSectionWithButton(toolkit, body, new GridData(SWT.FILL, SWT.FILL, true, true));
createSectionWithButton(toolkit, body, new GridData(SWT.FILL, SWT.FILL, true, true));

body.layout();
}

private void createSectionWithButton(FormToolkit toolkit, final Composite body, final GridData layoutData) {
Section section = createSection(toolkit, body, "Section");
section.setLayoutData(layoutData);
section.setClient(toolkit.createButton(section, "button", SWT.NONE));
}

private Section createSection(final FormToolkit toolkit, final Composite body, String title) {
Section section = toolkit.createSection(body, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
section.setText(title);
managedForm.addPart(new SectionPart(section));
section.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
managedForm.reflow(true);
}
});
return section;
}
}

有什么指点吗?甚至应该在哪里为部门或他们的 parent 或客户指定布局?提前致谢!

最佳答案

我终于找到了一位同事来研究这个,我们一起立即找到了解决方案,诀窍是简单地将 GridData 修改为 not grabExcessVerticalSpace 当部分折叠时:

private void createSectionWithButton(FormToolkit toolkit, final Composite body, final GridData layoutData) {
final Section section = createSection(toolkit, body, "Section", layoutData.grabExcessVerticalSpace);
section.setLayoutData(layoutData);
section.setClient(toolkit.createButton(section, "button", SWT.NONE));
}

private Section createSection(final FormToolkit toolkit, final Composite body, String title,
boolean shouldGiveUpVerticalSpaceWhenFolded) {
final Section section = toolkit.createSection(body, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
section.setText(title);
managedForm.addPart(new SectionPart(section));
if (shouldGiveUpVerticalSpaceWhenFolded) {
section.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
GridData gridData = (GridData) section.getLayoutData();
gridData.grabExcessVerticalSpace = e.getState();
}
});
}
section.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
managedForm.reflow(true);
}
});
return section;
}

我一直坚持我的想法,即必须可以通过某种方式用布局来定义它。我仍然有兴趣知道它是否是。

关于java - 两个 Eclipse UI Form 部分捕获多余的垂直空间并正确折叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2221428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com