有一个JTable
。我想知道它的行数。如何实现?
最佳答案
您可以使用 getRowCount()
方法:
Returns the number of rows that can be shown in the
JTable
, given unlimited space. If aRowSorter
with a filter has been specified, the number of rows returned may differ from that of the underlyingTableModel
.
Here你有一个例子:
import javax.swing.JTable;
public class Main {
public static void main(String[] argv) throws Exception {
Object[][] cellData = { { "1-1", "1-2" }, { "2-1", "2-2" } };
String[] columnNames = { "col1", "col2" };
JTable table = new JTable(cellData, columnNames);
int rows = table.getRowCount();
int cols = table.getColumnCount();
System.out.println(rows);
System.out.println(cols);
}
}
关于swing - 如何统计JTable的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42177966/