java – 改变SWT Composite的子级顺序

在我的情况下,我有两个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 );

希望它有帮助.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...