我正在使用 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");
}
}
我不知道为什么,我想知道如何解决这个问题,因为我必须切换回代码视图并删除很多标签,这让我浪费时间。