Making ArrayList to JTable
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 di开发者_JS百科splay them in a Swing application in the form of a table and perform sorting and filtering on them.
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.
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).
精彩评论