gpt4 book ai didi

java - 防止 SWT ScrolledComposite 吃掉它的部分 child

转载 作者:搜寻专家 更新时间:2023-10-30 21:07:24 26 4
gpt4 key购买 nike

我做错了什么?

这是我的代码的摘录:

public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL);
scrollBox.setExpandHorizontal(true);
mParent = new Composite(scrollBox, SWT.NONE);
scrollBox.setContent(mParent);
FormLayout layout = new FormLayout();
mParent.setLayout(layout);
// Adds a bunch of controls here
mParent.layout();
mParent.setSize(mParent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
}

...但是它剪掉了最后一个按钮: alt text

bigbrother82:那没用。

SCdF:我试过你的建议,现在滚动条不见了。我需要在这方面做更多的工作。

最佳答案

这是使用 ScrolledComposite 时的常见障碍。当它变得太小以至于必须显示滚动条时,客户端控件必须水平收缩以为滚动条腾出空间。这具有使某些标签换行的副作用,这会将以下控件进一步向下移动,从而增加了内容组合所需的最小高度。

您需要监听内容组合 (mParent) 上的宽度变化,在给定新内容宽度的情况下再次计算最小高度,然后调用 setMinHeight()具有新高度的滚动复合 Material 。

public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL);
scrollBox.setExpandHorizontal(true);
scrollBox.setExpandVertical(true);

// Using 0 here ensures the horizontal scroll bar will never appear. If
// you want the horizontal bar to appear at some threshold (say 100
// pixels) then send that value instead.
scrollBox.setMinWidth(0);

mParent = new Composite(scrollBox, SWT.NONE);

FormLayout layout = new FormLayout();
mParent.setLayout(layout);

// Adds a bunch of controls here

mParent.addListener(SWT.Resize, new Listener() {
int width = -1;
public void handleEvent(Event e) {
int newWidth = mParent.getSize().x;
if (newWidth != width) {
scrollBox.setMinHeight(mParent.computeSize(newWidth, SWT.DEFAULT).y);
width = newWidth;
}
}
}

// Wait until here to set content pane. This way the resize listener will
// fire when the scrolled composite first resizes mParent, which in turn
// computes the minimum height and calls setMinHeight()
scrollBox.setContent(mParent);
}

在监听大小变化时,请注意我们忽略了宽度保持不变的任何调整大小事件。这是因为内容高度的变化不会影响内容的最小高度,只要宽度相同即可。

关于java - 防止 SWT ScrolledComposite 吃掉它的部分 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35123/

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