Java – change the child order of SWT composite

In my case, I have two sashform children, but the problem applies to all composites

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);
    }    
}

I don't know in what order these methods will be known in advance How do you ensure that Child1 is on the left and child2 is on the right? Or, after creating the sashform, is there any way to change their order?

At present, my best idea is to put such placeholders:

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);
    }    
}

Solution

When you create Child1, check whether child2 has been instantiated If so, it means that Child1 is on the right, because it has been created, so you must do this:

child1.moveAbove( child2 );

I hope it helps

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>