java - ElementListSelectionDialog 没有元素

标签 java eclipse dialog swt jface

我正在尝试使用 ElementListSelectionDialog .我已经按照示例代码进行操作,但无论出于何种原因,对话框都会显示但没有选项

我的代码:

ElementListSelectionDialog dialog = 
      new ElementListSelectionDialog(shlSpriteCreator, new LabelProvider());
dialog.setMultipleSelection(false);
dialog.setIgnoreCase(true);
dialog.setAllowDuplicates(true);
dialog.setMessage("Select an AI");
dialog.setTitle("What AI to use?");
dialog.setElements(new String[]{"HELLO","GOODBYE"});
if (dialog.open() == Window.OK) {
    aiControllerLocation = (String) dialog.getFirstResult();
}

结果对话框:

Dialog with no options to select

我最初使用了一个类数组,但由于它不起作用,我用一个简单的字符串列表代替了,尽管据我所知是使用 LabelProvider类我应该能够使用任何对象,它将通过它的 toString() 表示显示。

最佳答案

这种类型的对话框在 Workbench UI 下正常工作。要正确运行此对话框,您应该使用示例代码

ElementListSelectionDialog dialog = 
    new ElementListSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), new LabelProvider());

关于java - ElementListSelectionDialog 没有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12126311/

相关文章:

java - 如何在 Java 项目中使用 Project Lombok

java - 如何防止我的数据库在执行时被清空

java - 如何告诉 Eclipse 忽略 : "No persistence.xml file found in project"

javascript - 如何将按钮传递到 Jquery 函数中?

python - 检查文件是否存在于 Python 2.7 中

java - 在 while 循环中等待用户操作 - JAVA

java - 无法建立 kmodule 的索引

java - 让 Eclipse 更喜欢嵌套类的静态导入

java - 如何通过命令行运行Maven/Gradle Web项目?

Android 对话框在旋转时崩溃