我很好奇为什么 DefaultTableModel 有一个
public void addRow(Object[] rowData)
但是没有
public Object[] getRow()
有没有一种方法可以获取行数据数组,而无需逐个循环遍历行单元格?
最佳答案
Is there a way to get an array of the row data without looping through the row cells one-by-one?
您需要创建一个自定义 TableModel 来支持此功能。
查看Row Table Model和 List Table Model它确实为您实现了此类功能。
好吧,实际上它返回的是 List
中的行,而不是 Array
,但您始终可以使用 List.toArray(...)
方法,如果你确实需要一个数组。
关于java: JTable DefaultTableModel addRow(Object[] rowData),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23822206/