0

我正在使用 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的 s,如下所示:

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

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

4

1 回答 1

1

好吧,Windowbuilder 用空的占位符填充布局。

例如:

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

于 2012-08-06T06:53:20.867 回答