【问题标题】:ElementListSelectionDialog has no elementsElementListSelectionDialog 没有元素
【发布时间】:2012-08-21 00:23:14
【问题描述】:

我正在尝试使用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();
}

结果对话框:

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

【问题讨论】:

    标签: java eclipse dialog swt jface


    【解决方案1】:

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

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

    【讨论】:

    • 哦,我明白了问题的根源。我关注了一篇关于 jface 对话框的错误博客文章。重新查阅文档,我注意到虽然从 jface 对话框继承,但 ElementListSelectionDialog 位于 org.eclipse.ui.dialogs 包中。我想我得自己写了。
    猜你喜欢
    • 2013-02-04
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    相关资源
    最近更新 更多