There is a JTable. I want to know the number of rows of it. How to achieve that ?
You can use the getRowCount() method:
Returns the number of rows that can be shown in the
JTable, given unlimited space. If aRowSorterwith a filter has been specified, the number of rows returned may differ from that of the underlyingTableModel.
Here you have one example:
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);
}
}
DefaultTableModel t=(DefaultTableModel)jTable1.getModel();
int number_of_rows = t.getRowCount();
note : if empty rows number_of_rows=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With