我在swt中新建一个Label的时候,想让它显示在原来的一个Label的上面,但是动态新建之后,它的层次总是在原来的Label下面(被原来的Label覆盖),该如何设置Label的层次(深度)?

解决方案 »

  1.   

    好象是没有的,不过你可以用其visible属性来控制2个label之间的显示
      

  2.   

    楼主这样的情况可以用 StackLayout 来实现, 我写了一段测试程序,仅供参考:
    public static void main(String[] args) {
     
             Display display = new Display();
             Shell shell = new Shell(display);
             shell.setLayout(new GridLayout());
     
             final Composite parent = new Composite(shell, SWT.NONE);
             parent.setLayoutData(new GridData(GridData.FILL_BOTH));
             final StackLayout layout = new StackLayout();
             parent.setLayout(layout);
            
             final Label oldLabel = new Label(parent, SWT.NONE);
             oldLabel.setText("Old Label");
             
             final Label newLabel = new Label(parent, SWT.NONE);
             newLabel.setText("New Label");
             
             layout.topControl = newLabel;
     
             Button b = new Button(shell, SWT.PUSH);
             b.setText("Show Label");
             b.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent arg0) {
    if(layout.topControl == newLabel){
    layout.topControl = oldLabel;
    }else{
    layout.topControl = newLabel;
    }
    parent.layout();
    }
              
             });
     
             shell.open();
             while (shell != null && !shell.isDisposed()) {
                     if (!display.readAndDispatch())
                             display.sleep(); 
             }       
     }
      

  3.   

    有一个moveAbove(Control c)的方法,可以移到某一组件之上,如果为null,则移到最上面,相同的还有moveBelow(Control C)
      

  4.   

    我用moveAbove(Control c)的方法实现了