gpt4 book ai didi

java - 对话框 - 打开关闭的对话框而不创建新对话框

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

这是一个简单得多的问题。

private static AplotBaseDialog dlg; 


public Object execute(final ExecutionEvent event) throws ExecutionException {
if (dlg == null){
try {
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
dlg = new AplotBaseDialog(shell, session);
}
catch {
}
dlg.open();
return null;
}

好的,上面的代码检查 dlg 是否为空。如果为空则创建一个新对话框。然后它打开对话框。

这在 dlg 为空时有效。但如果 dlg 不为空,我会在 dlg.open() 行收到错误。错误指向对话框类中的这段代码

  @Override
protected Control createContents(Composite parent) {
Control contents = super.createContents(parent); <==== Right Here
setTitle("Title");
setMessage("Message");
if (image != null) {
setTitleImage(image);
}
return contents;
}

所以我的问题是当 dlg != null 时如何打开对话框?

编辑添加一些错误消息

enter image description here

AplotBaseDialog 中的第 110 行

Control contents = super.createContents(parent);

AplotDialogHandler 中的第 48 行

dlg.open();

最佳答案

java.lang.IllegalArgumentException: Argument not valid

...

at org.eclipse.swt.widgets.Label.setImage(Label.java:337)

JavaDoc Label告诉你以下内容:

IllegalArgumentException -

ERROR_INVALID_ARGUMENT - if the image has been disposed

所以,看来您已经处理了您要设置的图像。

<小时/>

有两种解决方案:

  1. 等待处理图像,直到主应用程序关闭。
  2. 关闭对话框时丢弃该图像,但在重新打开对话框时创建一个新图像。

关于java - 对话框 - 打开关闭的对话框而不创建新对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13077153/

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