0
我需要在Eclipse rcp中的Scrollable Composite上繪製多個畫布,並將它們放入網格佈局中。我設法實現了這一點,但我堅持調整GridLayouts Cell-Size。調整GridLayout的單元大小 - 繪製多個畫布?
我想要的是網格動態調整每個畫布的大小(或至少手動設置大小),但使GridLayout填充父組件的完整空間。
我有什麼至今:
public class Test {
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final ScrolledComposite sComp = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
final Composite fillComp = new Composite(sComp, SWT.NONE);
GridLayoutFactory.createFrom(new GridLayout(10, true)).applyTo(fillComp);
for (int i = 0; i < 500; i++) {
final Canvas c = new Canvas(fillComp, SWT.DOUBLE_BUFFERED);
c.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setBackground(display.getSystemColor(new Random().nextInt(20)));
e.gc.fillRectangle(0, 0, 200, 200);
}
});
}
sComp.setContent(fillComp);
fillComp.pack();
shell.open();
shell.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
我假定父組件的佈局設置爲FillLayout的會做的伎倆,但它不工作。我想我需要使用GridData對象,但我在這裏有點迷路。