gpt4 book ai didi

java - 新复合 Material 未显示在对话框中

转载 作者:行者123 更新时间:2023-12-01 15:12:41 25 4
gpt4 key购买 nike

我正在尝试将新的组合添加到我的对话框中。我正在创建一个简单的按钮,我想将其放置在对话框中。我首先创建了一个方法来创建按钮区域。该方法调用一个方法来创建简单按钮。新按钮未显示在对话框中。

这是完整的代码

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

有人可以向我展示执行对话框之类的操作的方法的布局吗?

最佳答案

也许用您创建的 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);
}

关于java - 新复合 Material 未显示在对话框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12112440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com