就我而言,我有两个孩子 SashForm
,但问题适用于所有人 Composite
秒。
class MainWindow {
Sashform sashform;
Tree child1 = null;
Table child2 = null;
MainWindow(Shell shell) {
sashform = new SashForm(shell, SWT.NONE);
}
// Not called from constructor because it needs data not available at that time
void CreateFirstChild() {
...
Tree child1 = new Tree(sashform, SWT.NONE);
}
void CreateSecondChild() {
...
Table child2 = new Table(sashform, SWT.NONE);
}
}
我事先不知道这些方法的调用顺序。我怎样才能确定 child1
放在左边,和 child2
在右边?或者,有没有办法改变他们作为孩子的秩序 sashform
后 他们被创造了?
目前我最好的想法是放置这样的占位符:
class MainWindow {
Sashform sashform;
private Composite placeholder1;
private Composite placeholder2;
Tree child1 = null;
Table child2 = null;
MainWindow(Shell shell) {
sashform = new SashForm(shell, SWT.NONE);
placeholder1 = new Composite(sashform, SWT.NONE);
placeholder2 = new Composite(sashform, SWT.NONE);
}
void CreateFirstChild() {
...
Tree child1 = new Tree(placeholder1, SWT.NONE);
}
void CreateSecondChild() {
...
Table child2 = new Table(placeholder2, SWT.NONE);
}
}