我会设计类似于那些 Eclipse 但没有成功的 TitleAreaDialog,下面有两个屏幕截图,Eclipse 表单和我自己的表单,
我在获取顶部和底部分隔符时遇到问题,如果您注意到,Eclipse 表单没有提供边距,并且工作区有边距。
以我自己的形式,我的分隔符有一个边距
Eclipse 表格: http: //farm8.staticflickr.com/7437/9075688435_d5c49770fa_b.jpg
我自己的表格 http://farm4.staticflickr.com/3688/9077919366_8c25c40a79_b.jpg
这是我班级的源代码
public class CompteDialog extends TitleAreaDialog {
private Text idCompteText;
private Text libelleCompteText;
private Text ribCompteText;
private Text agenceCompteText;
public CompteDialog(Shell parentShell) {
super(parentShell);
}
@Override
public void create() {
super.create();
// Set the title
setTitle("Fiche comptes");
// Set the message
setMessage("Saisissez les informations relatives au compte",
IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
setTitleImage(ResourceManager.getPluginImage(
"dz.iaityahia.cieptalcars.matresorerie", "icons/wallet.png"));
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
// Champs ID
Label idCompteLabel = new Label(parent, SWT.NONE);
idCompteLabel.setText("Compte ID");
GridData gridData = new GridData(GridData.BEGINNING,
GridData.BEGINNING, true, false, 1, 1);
idCompteText = new Text(parent, SWT.BORDER);
idCompteText.setLayoutData(gridData);
idCompteText.setTextLimit(20);
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
// Champs libelle
Label libelleCompteLabel = new Label(parent, SWT.NONE);
libelleCompteLabel.setText("Libellé compte");
libelleCompteText = new Text(parent, SWT.BORDER);
libelleCompteText.setLayoutData(gridData);
// Champs Rib
Label ribCompteLabel = new Label(parent, SWT.NONE);
ribCompteLabel.setText("R.I.B");
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
ribCompteText = new Text(parent, SWT.BORDER);
ribCompteText.setLayoutData(gridData);
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
// Champs libelle
Label agenceCompteLabel = new Label(parent, SWT.NONE);
agenceCompteLabel.setText("Agence bancaire");
agenceCompteText = new Text(parent, SWT.BORDER);
agenceCompteText.setLayoutData(gridData);
// Create a bottom separator
Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true, 2, 1));
return parent;
}
@Override
protected Control createButtonBar(Composite parent) {
final Composite buttonBar = new Composite(parent, SWT.NONE);
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = false;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonBar.setLayout(layout);
GridData gridData = new GridData(GridData.FILL, GridData.END, true,
true, 2, 1);
buttonBar.setLayoutData(gridData);
/*
* org.eclipse.swt.graphics.Color magenta =
* Display.getDefault().getSystemColor(SWT.COLOR_MAGENTA);
* buttonBar.setBackground(magenta);
*/
// Create Add button
// Own method as we need to overview the SelectionAdapter
createOkButton(buttonBar, OK, "Add", true);
// Add a SelectionListener
// Create Cancel button
Button cancelButton = createButton(buttonBar, CANCEL, "Cancel", false);
// Add a SelectionListener
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setReturnCode(CANCEL);
close();
}
});
return buttonBar;
}
protected Button createOkButton(Composite parent, int id, String label,
boolean defaultButton) {
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
button.setFont(JFaceResources.getDialogFont());
button.setData(new Integer(id));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (isValidInput()) {
okPressed();
}
}
});
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
}
setButtonLayoutData(button);
return button;
}
private boolean isValidInput() {
boolean valid = true;
if (idCompteText.getText().length() == 0) {
setErrorMessage("Veuillez saisir le compte ID");
valid = false;
}
if (libelleCompteText.getText().length() == 0) {
setErrorMessage("Veuillez saisir le libellé du compte");
valid = false;
}
return valid;
}
@Override
protected boolean isResizable() {
return true;
}
}
有人能给我一个想法如何让 TiteAreaDialog 类似于 Eclipse 吗?
非常感谢