WindowBuilder添加了大量不需要的空标签

时间:2012-08-05 16:17:48

标签: java eclipse swt windowbuilder

我正在使用Google的WindowBuilder在Eclipse中为桌面Java / SWT应用程序创建UI。 我正在使用Mac OS X.

我有这个简单的类(为清楚起见,删除了导入):

public class CustomersTab extends Composite {
    CustomersList mCustomersList;
    CustomerBadge mCustomerBadge;
    private final Table mtable;

    public CustomersTab(final Composite parent, final int style) {
        super(parent, style);
        setLayout(new GridLayout(3, false));

        final Composite leftPanel = new Composite(this, SWT.NONE);
        leftPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        leftPanel.setLayout(new GridLayout(1, false));

        final Label lblRerchercher = new Label(leftPanel, SWT.NONE);
        lblRerchercher.setFont(SWTResourceManager.getFont("Lucida Grande", 13, SWT.BOLD | SWT.ITALIC));
        lblRerchercher.setText("Clients");
        mCustomersList = new CustomersList(leftPanel, SWT.NONE);
        mCustomersList.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));

        final Label label = new Label(this, SWT.SEPARATOR | SWT.VERTICAL);
        label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));

        final Composite rightPanel = new Composite(this, SWT.NONE);
        rightPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        rightPanel.setLayout(new GridLayout(1, false));

        mCustomerBadge = new CustomerBadge(rightPanel, SWT.NONE);
        mCustomerBadge.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

        final Label label_2 = new Label(rightPanel, SWT.NONE);
        label_2.setText("Détails");
        label_2.setFont(SWTResourceManager.getFont("Lucida Grande", 13, SWT.BOLD | SWT.ITALIC));

        mtable = new Table(rightPanel, SWT.BORDER | SWT.FULL_SELECTION);
        mtable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        mtable.setHeaderVisible(true);
        mtable.setLinesVisible(true);

        final Label label_1 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
        label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(this, SWT.NONE);

        final Label label_3 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
        label_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

        final Button btnNewButton = new Button(this, SWT.NONE);
        btnNewButton.setImage(SWTResourceManager.getImage(CustomersTab.class, "/img/user_add.png"));
        btnNewButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
        btnNewButton.setText("Nouveau client");
        new Label(this, SWT.NONE);

        Composite composite = new Composite(this, SWT.NONE);
        composite.setLayout(new GridLayout(1, false));

        Button btnModifierCeClient = new Button(composite, SWT.NONE);
        btnModifierCeClient.setImage(SWTResourceManager.getImage(CustomersTab.class, "/img/user_edit.png"));
        btnModifierCeClient.setText("Modifier ce client");
    }
}

当我使用WindowBuilder构建我的UI时,有时它会添加许多未使用的Label,如下所示:

public class CustomersTab extends Composite {
    CustomersList mCustomersList;
    CustomerBadge mCustomerBadge;
    private final Table mtable;

    public CustomersTab(final Composite parent, final int style) {
        super(parent, style);
        setLayout(new GridLayout(3, false));

        final Composite leftPanel = new Composite(this, SWT.NONE);
        leftPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        leftPanel.setLayout(new GridLayout(1, false));

        final Label lblRerchercher = new Label(leftPanel, SWT.NONE);
        lblRerchercher.setFont(SWTResourceManager.getFont("Lucida Grande", 13, SWT.BOLD | SWT.ITALIC));
        lblRerchercher.setText("Clients");
        mCustomersList = new CustomersList(leftPanel, SWT.NONE);
        mCustomersList.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));

        final Label label = new Label(this, SWT.SEPARATOR | SWT.VERTICAL);
        label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));

        final Composite rightPanel = new Composite(this, SWT.NONE);
        rightPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        rightPanel.setLayout(new GridLayout(1, false));

        mCustomerBadge = new CustomerBadge(rightPanel, SWT.NONE);
        mCustomerBadge.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);
        new Label(mCustomerBadge, SWT.NONE);

        final Label label_2 = new Label(rightPanel, SWT.NONE);
        label_2.setText("Détails");
        label_2.setFont(SWTResourceManager.getFont("Lucida Grande", 13, SWT.BOLD | SWT.ITALIC));

        mtable = new Table(rightPanel, SWT.BORDER | SWT.FULL_SELECTION);
        mtable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        mtable.setHeaderVisible(true);
        mtable.setLinesVisible(true);

        final Label label_1 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
        label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        new Label(this, SWT.NONE);

        final Label label_3 = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
        label_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

        final Button btnNewButton = new Button(this, SWT.NONE);
        btnNewButton.setImage(SWTResourceManager.getImage(CustomersTab.class, "/img/user_add.png"));
        btnNewButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
        btnNewButton.setText("Nouveau client");
        new Label(this, SWT.NONE);

        Composite composite = new Composite(this, SWT.NONE);
        composite.setLayout(new GridLayout(1, false));

        Button btnModifierCeClient = new Button(composite, SWT.NONE);
        btnModifierCeClient.setImage(SWTResourceManager.getImage(CustomersTab.class, "/img/user_edit.png"));
        btnModifierCeClient.setText("Modifier ce client");
    }
}

我不知道为什么,而且我想知道如何解决这个问题,因为我必须切换回代码视图并删除相当多的标签,这让我浪费时间。

1 个答案:

答案 0 :(得分:1)

嗯,Windowbuilder用空占位符填充布局。

例如:

你有3列,并创建了6个控件,这意味着前两行用控件填充。如果您现在添加一个WindowBuilder的控件不在第3行第一列(布局中的下一个“空格”),但是例如在第5行第2列,Windowbuilder必须为完整的第3列创建这些虚拟标签第4行和第1行的第一列,因此它将添加7个这些虚拟标签。知道了吗?