Making ArrayList to JTable

[亡魂溺海] 提交于 2019-12-30 07:05:07

问题


I have an

ArrayList<Map<String, Object>>

Object, I need to display the content of this array in a JTable.

The Map - Key is the column name and Object is the data, how can I put it up?

Baiscally the Map contains multiple-rows from a table and all the rows are added to the array list, now I need to display them in a Swing application in the form of a table and perform sorting and filtering on them.


回答1:


For datas embed your list in a TableModel. A DefaultTableModel is best.

For columns, embed your list in a TableColumnModel. Best is a DefaultTableModel.

Then use the jtable constructor to use that.




回答2:


ArrayList<Map<String, Object>>

This sounds like the wrong model for the job, there is not really a sensible way of turning this into a single table. Perhaps you mean

Map<String, List<Object>>

This would make a lot more sense. Now one single key (the column name) is mapped to multiple values (the column values).



来源:https://stackoverflow.com/questions/4279631/making-arraylist-to-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!