gpt4 book ai didi

swing - 如何统计JTable的行数?

转载 作者:行者123 更新时间:2023-12-04 00:36:08 26 4
gpt4 key购买 nike

有一个JTable。我想知道它的行数。如何实现?

最佳答案

您可以使用 getRowCount() 方法:

Returns the number of rows that can be shown in the JTable, given unlimited space. If a RowSorter with a filter has been specified, the number of rows returned may differ from that of the underlying TableModel.

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/

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