I’m trying to let a JTable load from data stored in a ArrayList with HashMaps. The code looks something like
private ArrayList<HashMap> menuLijst;
private JPanel tablePanel;
//some init
tablePanel = new JPanel();
then, this is some random data, just to make sure it works.
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);
so that’s how my HashMap looks like, which is kind of superfluous to know, since the JTabel does not depend on pre-defined size-data.
All together, my question is, how to put data from the ArrayLists with HashMaps in the JTable.
I have tried some options but it didn’t work out as it should be.
Thanks in advance.
Either you just create your own
TableModelimplementation (or extend from one of the available classes), or you must use another data structure (see the available constructors onDefaultTableModel).But creating your
TableModelwould be rather straight-forward with this data structure as soon as you find a mechanism to determine the column order as aHashMapas no ordering.The Swing table tutorial contains a section on creating
TableModelinstances