2

//我在滚动合成中有一个合成。

final Composite c = new Composite(scrolledComposite, SWT.NONE); //1
c.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
c.setLayout(new GridLayout(1, false));

//我有一个for循环,将复合材料添加到复合材料c

for(int i = 0; i<100; i++){ 

    Composite b = new Composite(c, SWT.BORDER);
    b.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION));
    b.setLayout(new GridLayout(2, false));
    b.setBounds(112, 70, 268, 69);

//然后将一些控制器添加到该内部组合中

    Label lblNewLabel_2 = new Label(b, SWT.NONE);
    lblNewLabel_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 4));
    Image img = new Image(Display.getCurrent(), result.get(i).getPicturePath());


//.... more controllers.

// 最后我结束循环并将最外面的合成添加到滚动合成中。

} // end loop           
    scrolledComposite.setContent(c); //setter content!
    scrolledComposite.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));

这一切都很好,几乎。我的问题是内部复合不会响应 setBounds 方法。无论我在其中写什么,我都无法扩展它。我怀疑这与布局有关。

有人有线索吗?

提前致谢。

彼得

4

2 回答 2

3

布局是设置复合子的大小和位置的对象,因此您不必调用setBounds()它们中的每一个。查看了解 SWT 中的布局

SWT 应用程序中布局的目的是什么?

于 2011-12-13T21:20:55.247 回答
0

考虑在您的外部面板中使用 Resize 侦听器来调整您的内部面板。

_outerPanel.addListener(SWT.Resize, new Listener() {
    public void handleEvent(Event e) {
        computePanelSize();  // computes the inner panel size
    }
});
于 2011-12-24T17:48:41.990 回答