代码之家  ›  专栏  ›  技术社区  ›  Alexey Romanov

swt复合材料子结构的变阶

  •  11
  • Alexey Romanov  · 技术社区  · 15 年前

    我有两个孩子 SashForm ,但这个问题适用于所有人 Composite S.

    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);
        }    
    }
    
    1 回复  |  直到 15 年前
        1
  •  14
  •   Mario Marinato    15 年前

    创建child1时,请检查child2是否已实例化。如果是,则表示child1位于右侧,因为它是稍后创建的,因此您必须执行以下操作:

    child1.moveAbove( child2 );
    

    希望有帮助。