你好,我的问题是,我有一个特定类的列表,我想将其中的值绑定(bind)到jtable(它们添加的顺序现在并不重要) 列表中的类如下
public HighScore(int score, int amountofplayers, String playerName,String dateString) {
this.score = score;
this.amountofplayers = amountofplayers;
this.playerName = playerName;
this.dateString = dateString;
}
返回列表的函数是
public ArrayList<HighScore> GetHighScores()
{
ArrayList<HighScore> highscores = new ArrayList<HighScore>();
//get highscores from databse
//insert some test values
highscores.add(new HighScore(125, 2, "Piet","20-10-2015"));
highscores.add(new HighScore(167, 2, "Henk", "19-10-2015"));
highscores.add(new HighScore(278, 2, "Jan", "11-10-2015"));
return highscores;
}
所以现在我想将所有这些高分添加到我的 Jtable1 中,该 Jtable1 位于 jpannel 中。最简单/最有效的方法是什么
最佳答案
如果必须创建 JTable 对象,最简单的方法是使用它的构造函数之一。
有两个直接接受数据的 JTable 构造函数(SimpleTableDemo
使用第一个):
JTable(Object[][] rowData, Object[] columnNames)
JTable(Vector rowData, Vector columnNames)
rowData
必须将对象放置在您希望显示的位置。例如,要获取第二行第一列的对象,JTable 将执行 rowData[1][0]
(它遵循以下形式 rowData[row][col]
).
关于java - 将 List<Class> 中的值添加到 Jtable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33237566/