gpt4 book ai didi

java - Java AbstractTableModel 的 getValueAt 方法

转载 作者:行者123 更新时间:2023-12-01 07:05:16 33 4
gpt4 key购买 nike

我需要有关 getValue 方法的帮助

我从文件中读取并将值存储在

 public List<Object[]> students;

现在我想将所有这些值添加到我的 JTable

 @Override
public Object getValueAt(int row, int col) {
//return data[row][col];
// Here I have to get data from students
}

通常从很多例子中我看到他们使用 Object[][] data为了做这种事这可能是这样的

//return data[row][col];

但是因为我从一个文件中读取我想要 List<Object[]> students;

知道如何在 getValueAt 方法中实现它吗?

我的解决方案是这样

@Override
public Object getValueAt(int row, int col) {
//return data[row][col];
for(Object[] j: students)
{
return j[col];
}
return null;
}

但这只会采用第一个对象,并将分配给我的 JTable 中的所有行

最佳答案

怎么样:

@Override
public Object getValueAt(int row, int col) {
return students.get(row)[col];
}

关于java - Java AbstractTableModel 的 getValueAt 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26831179/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com