例如  在Group group对象上  动态生成过几个Text text组件现在想在group上移除这个text组件  请问 有对应的方法吗 就像 group.XXX();这样的  API 我看了一下 也有找到合适的高手请指教

解决方案 »

  1.   

    随便看看,直接dispose掉就行了package test;import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.events.SelectionListener;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Group;import cc.component.CCShell;public class Test4Group {
    public static void main(String[] args) {
    Display display = new Display();
    final CCShell shell = new CCShell(display, SWT.CLOSE);
    shell.setBounds(200, 200, 300, 380);
    final Group gp = new Group(shell, SWT.SHADOW_ETCHED_IN);
    gp.setBounds(10, 10, 280, 260);
    gp.setText("group");
    Button btn = new Button(gp, SWT.NONE);
    btn.setText("button1");
    btn.setBounds(10, 10, 80, 20);
    btn = new Button(gp, SWT.NONE);
    btn.setText("button2");
    btn.setBounds(10, 40, 80, 20);
    btn.addSelectionListener(new SelectionListener() {

    @Override
    public void widgetSelected(SelectionEvent arg0) {
    Control[] ctrl = gp.getChildren();

    for (int i = 0;i<ctrl.length;i++) {
    if (ctrl[i] instanceof Button && ((Button)ctrl[i]).getText().equals("button1")) {
    ctrl[i].dispose();
    break;
    }
    }
    }

    @Override
    public void widgetDefaultSelected(SelectionEvent arg0) {
    // TODO Auto-generated method stub

    }
    });

    shell.open();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    } display.dispose();
    }}