java – 改变SWT Composite的子级顺序
发布时间:2020-05-27 05:00:12 所属栏目:Java 来源:互联网
导读:在我的情况下,我有两个SashForm的孩子,但问题适用于所有复合材料. class MainWindow { Sashform sashform; Tree child1 = null; Table child2 = null; MainWindow(Shell shell) { sashform = new SashForm(shell, SW
|
在我的情况下,我有两个SashForm的孩子,但问题适用于所有复合材料. 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);
}
}
解决方法当您创建child1时,请检查child2是否已被实例化.如果是这样,它意味着child1在右边,因为它已经被创建了,所以你必须这样做:child1.moveAbove( child2 ); 希望它有帮助. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
