SWT - 如何重新调整/设置位于另一个复合材料内的Composite的大小?

时间:2011-12-13 17:21:48

标签: java swt windowbuilder

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

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方法。无论我在写什么,我都无法扩展它。我怀疑这与布局有关。

任何人都有线索?

提前致谢。

皮特

2 个答案:

答案 0 :(得分:3)

布局是设置复合子项的大小和位置的对象,因此您不必为每个子项调用setBounds()。查看Understanding Layouts in SWT

What is the purpose of Layout in SWT applications?

答案 1 :(得分:0)

考虑外部面板中的Resize侦听器,让它调整内部面板。

_outerPanel.addListener(SWT.Resize, new Listener() {
    public void handleEvent(Event e) {
        computePanelSize();  // computes the inner panel size
    }
});