我做错了什么?
这是我的代码摘录
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:没有工作.
SCdF:我试过你的建议,现在滚动条已经消失了.我需要更多的工作.
解决方法
当使用ScrolledComposite时,这是一个常见的障碍.当SC变得如此之小以至于必须显示滚动条时,客户端控件必须水平收缩以为滚动条腾出空间.这具有使一些标签换行的副作用,这使得以下控件进一步向下移动,这增加了内容复合体所需的最小高度.
您需要监听内容复合(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); }
在侦听大小更改时,请注意,我们忽略宽度保持不变的任何大小调整事件.这是因为内容高度的变化不会影响内容的最小高度,只要宽度相同即可.