【发布时间】:2014-10-10 15:25:53
【问题描述】:
我在尝试从“确定”按钮的选择侦听器访问 SWT 对话框中的文本字段中的字段值时收到以下异常。
org.eclipse.swt.SWTException: Widget is disposed
我可以理解该错误是因为当我尝试访问 Dialog 时它已被释放。但我还没有明确调用处置外壳。
对话框是否在单击“确定”按钮时自动释放?有什么办法可以覆盖它吗?还是我在这里做错了什么?
感谢任何帮助或指示。相关代码sn-p如下:
public class MyDialog extends Dialog {
/** The file Name Text field. */
private Text fileNameText;
/** The constructor. **/
protected MyDialog(Shell parentShell) {
super(parentShell);
}
/** Create Dialog View. **/
protected Control createDialogArea(Composite parent) {
Composite mainComposite = (Composite) super.createDialogArea(parent);
fileNameText = new Text(mainComposite, SWT.BORDER);
fileNameText.setText("");
fileNameText.setBounds(0, 20, 428, 20);
return mainComposite;
}
/** Override method to set name and listener for 'OK' button. **/
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button submitButton = getButton(IDialogConstants.OK_ID);
submitButton.setText("Review");
setButtonLayoutData(submitButton);
// Perform Selected CleanUp activity on Submit Click.
submitButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
// do something.
if (fileNameText.getText().isEmpty()) {
return;
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
}
【问题讨论】:
标签: java eclipse eclipse-plugin swt jface