0

嗨,我在填充 TableModel 时遇到问题,我不明白问题出在哪里

这是我的方法

 private TableModel buildTableModel(List<Player> result) {
        // build the columns
        Vector<String> columnNames = new Vector<String>();
        //int columnCount = metaData.getColumnCount();
        //for (int column = 1; column <= columnCount; column++) {
        //    columnNames.add(metaData.getColumnName(column));
        //}

        columnNames.add("playerid");
        columnNames.add("squeezePlay");
        columnNames.add("weakShowdown");
        columnNames.add("numberOfPlays");
        columnNames.add("playsWithFriends");
        columnNames.add("suspend");
        columnNames.add("grade");


        // data of the table
        Vector<Vector<Object>> data = new Vector<Vector<Object>>();
        while (result.iterator().hasNext()) {
            Player player = result.iterator().next();

            Vector<Object> vector = new Vector<Object>();

             vector.add((Object) player.GetId());
             vector.add((Object) player.GetSqueezePlay());
             vector.add((Object) player.GetWeakShowdown());
             vector.add((Object) player.GetNumberOfPlays());
             vector.add((Object) player.GetPlaysWithFriends());
             vector.add((Object) player.GetSuspended());
             vector.add((Object) player.GetGrade());

             data.add(vector);
        }

        return new DefaultTableModel(data, columnNames);

    }

注意:无论有没有Object铸造,桌子仍然不起作用..

请建议任何替代解决方案来填充 TableModel。

谢谢!!

4

1 回答 1

4

每次您打电话时,result.iterator()您都在阅读列表的开头。相反,使用这个:

for (Player player : result)
于 2013-03-24T22:35:56.370 回答