对话框中未显示新的组合

5ssjco0h  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(514)

我正在尝试向对话框中添加新的合成。我正在创建一个简单的按钮,我想把它放在对话框中。我首先创建了一个方法来创建按钮区域。此方法正在调用一个方法来创建简单按钮。对话框中没有显示“新建”按钮。
这是完整的代码

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中这样的事情可能吗?

有人能给我展示一下对话框的布局吗?

uqdfh47h

uqdfh47h1#

也许这样会更干净,而不是 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);
}

相关问题