【发布时间】:2012-05-21 17:29:58
【问题描述】:
我正在尝试让 JTable 从存储在带有 HashMaps 的 ArrayList 中的数据中加载。代码看起来像
private ArrayList<HashMap> menuLijst;
private JPanel tablePanel;
//some init
tablePanel = new JPanel();
那么,这是一些随机数据,只是为了确保它有效。
this.menuList = new ArrayList();
// hashmap
HashMap hm1 = new HashMap();
HashMap hm2 = new HashMap();
hm1.put("question", "Contact");
hm1.put("query", "select contact from tim");
hm1.put("message", "contact");
hm2.put("question", "Sales");
hm2.put("query", "select sales from tim");
hm2.put("message", "sales");
menuList.add(hm1);
menuList.add(hm2);
这就是我的 HashMap 的样子,这有点多余,因为 JTabel 不依赖于预定义的大小数据。
总的来说,我的问题是,如何将 ArrayLists 中的数据与 HashMaps 放在 JTable 中。
我尝试了一些选项,但没有达到应有的效果。
提前致谢。
【问题讨论】:
-
试图使用 Dacwe 的评论,但同时他删除了它。
标签: java swing arraylist hashmap jpanel