Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SWT/JFace对话框中的OK按钮选择侦听器出错_Java_Eclipse_Eclipse Plugin_Swt_Jface - Fatal编程技术网

Java SWT/JFace对话框中的OK按钮选择侦听器出错

Java SWT/JFace对话框中的OK按钮选择侦听器出错,java,eclipse,eclipse-plugin,swt,jface,Java,Eclipse,Eclipse Plugin,Swt,Jface,当我试图从SWT对话框中的文本字段,从“确定”按钮的选择侦听器访问字段值时,收到以下异常 org.eclipse.swt.SWTException: Widget is disposed 我可以理解错误是因为当我试图访问对话框时,该对话框已被释放。但我还没有打任何明确的电话来处理这个外壳 单击“确定”按钮时是否自动释放对话框?有什么方法可以覆盖它吗?还是我做错了什么 感谢您的帮助或指点。下面是相关的代码片段: public class MyDialog extends Dialog {

当我试图从SWT对话框中的文本字段,从“确定”按钮的选择侦听器访问字段值时,收到以下异常

org.eclipse.swt.SWTException: Widget is disposed
我可以理解错误是因为当我试图访问对话框时,该对话框已被释放。但我还没有打任何明确的电话来处理这个外壳

单击“确定”按钮时是否自动释放对话框?有什么方法可以覆盖它吗?还是我做错了什么

感谢您的帮助或指点。下面是相关的代码片段:

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) {
            }
        });
    }
}

是,单击“确定”按钮时,对话框将自动释放,不,您不应停止此操作

您必须做的是在释放对话框之前覆盖
ok并保存文本值:

private String fileNameValue;

....

@Override
protected void okPressed()
{
  fileNameValue = fileNameText.getText();

  super.okPressed();
}

谢谢成功了。唯一的问题是,视图有许多输入,在调用
okPressed
方法之前,所有这些都需要分配给变量。您可以使用自动设置类中的字段。谢谢。。我也要看一看。