WindowBuilder добавляет МНОГО ненужной пустой метки.

Я использую Google WindowBuilder для создания пользовательских интерфейсов в Eclipse для настольных приложений Java/SWT. Я использую 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, иногда случается, что он добавляет много неиспользуемых 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");
    }
}

Я понятия не имею, почему, и я хотел бы знать, как это исправить, потому что мне приходится переключаться обратно в представление кода и довольно часто удалять метки, что заставляет меня тратить время.


person Benoit Duffez    schedule 05.08.2012    source источник


Ответы (1)


Что ж, Windowbuilder заполняет макет пустыми заполнителями.

Например:

У вас есть 3 столбца и создано 6 элементов управления, это означает, что первые две строки заполнены вашими элементами управления. Если теперь вы добавите элемент управления с помощью WindowBuilder не в первый столбец 3-й строки (который будет следующим «пробелом» в вашем макете), а, например, во 2-м столбце 5-й строки, Windowbuilder должен создать эти фиктивные метки для полных 3-го и 4-й строки и для первого столбца пятой строки, поэтому он добавит 7 таких фиктивных меток. Понятно?

person Tom Seidel    schedule 06.08.2012
comment
Это не моя проблема. Смотрите мой 1-й код, new Label(mCustomerBadge, SWT.NONE); нет. Если я добавлю новый виджет с помощью WindowBuilder, он добавит примерно 10 раз: new Label(mCustomerBadge, SWT.NONE);. Потом еще 10 раз. Если я их не удалю, то добавятся сотни строк этого бесполезного кода. Это не заполнение пустых ячеек в GridLayout, это действительно добавление материала туда, где он не должен. - person Benoit Duffez; 06.08.2012
comment
Не могли бы вы опубликовать фрагмент, который показывает проблему? - Код, который вы разместили, не компилируется... - person Tom Seidel; 06.08.2012
comment
Здесь вы найдете код для 3 файлов: pastebin.com/cEf422qG Я мог бы дать больше кода, но я думаю вы сможете воспроизвести проблему без дополнительного кода. Класс L предназначен для ведения журнала, удалите эти строки. Скажите, если мне нужно предоставить больше. Большое спасибо. - person Benoit Duffez; 06.08.2012