我正在尝试将新的复合添加到对话框中。我正在创建一个简单的按钮,我想将它放在对话框中。我首先创建了一个创建Button区域的方法。此方法调用方法来创建简单按钮。新按钮未显示在对话框中。
这是完整的代码
public class AplotBaseDialog extends TitleAreaDialog {
private TCSession session= null;
public AplotBaseDialog(Shell parentShell, TCSession theSession) {
super(parentShell);
session = theSession;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
composite.setLayout(layout);
// The text fields will grow with the size of the dialog
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.BEGINNING;
Label label1 = new Label(composite, SWT.NONE);
label1.setText("First Name");
label1.setLayoutData(gridData);
gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.CENTER;
Label label2 = new Label(composite, SWT.NONE);
label2.setText("Last Name");
label2.setLayoutData(gridData);
gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.END;
Button button1 = new Button(composite, SWT.PUSH);
button1.setText("Button 5");
button1.setLayoutData(gridData);
return composite;
}
protected void createButtonArea(Composite parent){
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.CENTER;
parent.setLayoutData(gridData);
createOkButton(parent);
}
protected Button createOkButton(Composite parent) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
button.setText("Test Button");
setButtonLayoutData(button);
return button;
}
}
为什么测试按钮没有显示在对话框中?
在SWT / Jface中甚至可以这样吗?
有人可以告诉我方法的布局来做对话吗?
答案 0 :(得分:1)
可能更干净的是,您创建的createButtonArea()
方法实际上覆盖了createButtonsForButtonBar
方法。这将更加SWT友好。
/**
* Create contents of the button bar.
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, "Test Button",
true);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}