gpt4 book ai didi

java - SWT:扩展条的宽度

转载 作者:行者123 更新时间:2023-12-01 13:45:18 32 4
gpt4 key购买 nike

目前我正在使用 SWT 并尝试实现一个扩展栏:

    protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);

ExpandBar bar = new ExpandBar(container, SWT.V_SCROLL);

Composite newConstraint = new Composite(bar, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
newConstraint.setLayout(gridLayout);

Label sourcelbl = new Label(newConstraint, SWT.NONE);
sourcelbl.setImage(getMyImage("source.png"));
sourcelbl.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER,
true, false));

Label spacelbl = new Label(newConstraint, SWT.NONE);

Label targetlbl = new Label(newConstraint, SWT.NONE);
targetlbl.setImage(getMyImage("target.png"));
targetlbl.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER,
true, false));

ListViewer lvSource = new ListViewer(newConstraint);
lvSource.setContentProvider(new ConstraintDialogContentProvider());
lvSource.setLabelProvider(new ConstraintDialogLabelProvider());
lvSource.setInput(fm);

Combo constrainType = new Combo(newConstraint, SWT.NONE);
constrainType.setItems(new String[] { "require", "exclude" });
constrainType.setLayoutData(new GridData(GridData.CENTER,
GridData.CENTER, true, false));

ListViewer lvTarget = new ListViewer(newConstraint);
lvTarget.setContentProvider(new ConstraintDialogContentProvider());
lvTarget.setLabelProvider(new ConstraintDialogLabelProvider());
lvTarget.setInput(fm);

ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0);
item0.setText("New Constraint");
item0.setHeight(newConstraint.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
item0.setControl(newConstraint);

omposite existingConstraints = new Composite(bar, SWT.NONE);
gridLayout = new GridLayout();
gridLayout.numColumns = 2;
existingConstraints.setLayout(gridLayout);

........

ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 1);
item1.setText("Existing Constraints");
item1.setHeight(existingConstraints.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
item1.setControl(existingConstraints);

item0.setExpanded(true);
bar.setSpacing(8);

return container;
}

问题是宽度,它似乎没有被计算:

enter image description here

没有扩展栏,一切正常,宽度会自动计算:

enter image description here

如何让extendbar计算宽度???

干杯,菲尔

最佳答案

ExpandBar 大小计算似乎仅考虑了 ExpandItem 文本的大小,而忽略了项目中控件的大小。

您必须重写 ExpandBar.computeSize 方法来更改此设置(还必须重写 ExpandBar.checkSubclass 来阻止拒绝您的子类)。

或者您可以在 ExpandItems 的文本末尾添加空格来伪造计算的大小。

关于java - SWT:扩展条的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20410308/

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