将HashMap转换为DefaultListModel [英] HashMap into DefaultListModel

查看:156
本文介绍了将HashMap转换为DefaultListModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

HashMap<String, String> inst1 = new HashMap(instructorIO.getInstructors());
instListModel = new DefaultListModel<String>(inst1.values());

我收到错误:

DepartmentProject.java:69: error: constructor DefaultListModel in class DefaultListModel<E> cannot be applied to given types;
    required: no arguments
    found: Collection<String>
    reason: actual and formal argument lists differ in length
    where E is a type-variable:
    E extends Object declared in class DefaultListModel

任何人都可以帮我吗?

推荐答案

DefaultListModel 只有一个不带参数的构造函数;你不能传递你想要的值作为构造函数arg。
您必须创建DefaultListModel然后再填充它,例如:

DefaultListModel only has a constructor that takes no arguments; you can't pass the values you want as a constructor arg. You will have to create the DefaultListModel and then populate it afterward, for example:

HashMap<String, String> inst1 = new HashMap(instructorIO.getInstructors());
instListModel = new DefaultListModel<String>();
for (String value : inst1.values())
{
    instListModel.addElement(value);
}

这篇关于将HashMap转换为DefaultListModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆