org.eclipse.swt.SWTExecption:Widget已处理

时间:2013-03-08 15:08:18

标签: widget swt

我的用户从主应用程序工作区中选择数据。数据存储在可写列表中。然后,用户继续打开对话框以在表格中显示所选数据。 当我的用户第一次打开对话框时。一切都很好,事情按计划进行。但是当他们关闭对话框然后重新打开它时。我收到以下错误。

enter image description here

允许他们关闭对话框并选择更多数据。然后再次打开对话框以查看旧数据和新数据。

代码用于错误的步骤顺序。

  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);  
    Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    final GridLayout gridLayout = new GridLayout();

    gridLayout.marginWidth = 15;
    gridLayout.marginHeight = 10;
    composite.setLayout(gridLayout);

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    composite.setLayoutData(gridData);
    createTopButtons(composite);
    createTableViewer(composite);
    createRemoveButtons(composite);
    updateTableViewer();
    return composite;
 }

在错误中,我们可以看到它来自updateTableViewer

public void updateTableViewer() {
  setRemoveButtonVisibility();
  setRemoveAllButtonVisibility();
  setPlotButtonVisibility();
  setPDFButtonVisibility();
}

在错误中,我们看到它来自setRemoveButtonVisibility();

public void setRemoveButtonVisibility() {
  if (AplotDataModel.getInstance().getSize() > 0) {
     removeButton.setVisible(true);
  }
  else {
     removeButton.setVisible(false);
  }
}

这是它指向的行:

removeButton.setVisible(true);

if条件是检查存储用户选择的数据的可写列表。如果列表为空,则按钮不显示,如果有数据,则按钮显示。

以下是关闭对话框按钮的代码:

protected void createButtonsForButtonBar(Composite parent) {
  Button okButton = createButton(parent, OK, "Close Aplot", true);
  okButton.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent e) {
        viewer = null;
        close();
     }
  });
}

有什么想法吗?

2 个答案:

答案 0 :(得分:5)

使用close()隐藏对话框,而不是使用getShell().setVisible(false)。因为您正在重复使用相同的对话框,所以不应该关闭它。如果你关闭对话框,然后将其关闭,你应该在每次需要打开它时创建一个新的对话框。

答案 1 :(得分:0)

确保在关闭shell后不要尝试读取任何信息。 例如:

System.out.println(combo.getText())
shlUpload.close();
ImportGroup window = new ImportGroup();
window.open(combo.getText());

一旦你关闭shlUpload它就不会再看到对象“combo”了。 奥斯汀

相关问题