防止他ScrolledComposite吃它的一部分的孩子
题
我做错了什么?
这里是摘自我的代码:
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));
}
...但是它剪辑的最后一个按钮:
bigbrother82:没有工作。
新加坡民防部队:我想你的建议,现在滚动都不见了。我需要一些工作。
解决方案
这是一个常见的障碍时使用 ScrolledComposite
.当它变得这么小的滚动条必须显示,客户控制已经萎缩的水平,使用滚动条。这有副作用的一些标签包裹线,其中转移以下控制越走越远,这增加了最低高度需求的内容的复合物。
你需要聆听的宽度变化上的内容复(mParent
),计算的最低高度再次给予新的内容的宽度,并呼叫 setMinHeight()
在滚动的复合新的高度。
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);
}
在聆听大小的变化,注意到,我们忽略任何调整活动,宽度保持不变。这是因为高度变化的内容并不会影响 最低 高度的内容,只要宽度是相同的。
其他提示
如果我没有记错的话你需要换的
mParent.layout();
和
mParent.setSize(mParent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
所以你必须:
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.setSize(mParent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
mParent.layout();
}
你不需要重新计算的大小scrollBox后布局?
试图设置。setMinWidth。setMinHeight在ScrolledComposite一次的布局已经完成,通过它的大小主要复合材料。
不隶属于 StackOverflow