gpt4 book ai didi

java - 如何按确定按钮将数据存储在 TitleAreaDialog 中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:37 25 4
gpt4 key购买 nike

为什么在下面的代码中(扩展 TitleAreaDialog 的类的一部分):

@Override  
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
this.getButton(IDialogConstants.OK_ID).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
okPressed();
}
});
}

@Override
protected void okPressed() {
saveInput();
super.okPressed();
}

private void saveInput(){
firstNameSelected = firstNameCombo.getText();
lastNameSelected = lastNameCombo.getText();
}

当我按下 OK 按钮时出现以下异常:

org.eclipse.swt.SWTException: Widget is disposed at org.eclipse.swt.SWT.error(SWT.java:4361) at org.eclipse.swt.SWT.error(SWT.java:4276) at org.eclipse.swt.SWT.error(SWT.java:4247) at org.eclipse.swt.widgets.Widget.error(Widget.java:468) at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340) at org.eclipse.swt.widgets.Combo.getText(Combo.java:1006)

行内: firstNameSelected = firstNameCombo.getText(); of saveInput?
为什么在选择时放置小部件?

最佳答案

尝试完全删除 createButtonsForButtonBar(Composite parent) 方法。该对话框应自行调用 okPressed

此外,我认为调用 super.okPressed() 不是必需的。至少我从不使用它。只需调用 this.close() 即可。

这是我使用的简单模板:

public class OptionsDialog extends Dialog {

public OptionsDialog(Shell parentShell)
{
super(parentShell);
setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
setBlockOnOpen(true);
}

protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);

GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 5;
layout.marginWidth = 10;

composite.setLayout(layout);

GridData gridData = new GridData();
gridData.widthHint = 500;

composite.setLayoutData(gridData);

createContent();

return composite;
}

private void createContent()
{
/* ADD WIDGETS */
}

protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setText("Options");
}

public void okPressed()
{
/* SAVE VALUES */
this.close();
}

/* GETTERS AND SETTERS/ */

}

关于java - 如何按确定按钮将数据存储在 TitleAreaDialog 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12731454/

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