In this java tutorial you will learn how to get the number of rows and columns in JTable.
Getting the Number of Rows and Columns in JTable
In this java tutorial you will learn how to get the number of rows and columns in JTable.
This program simply helps us for getting the number of rows and columns from the JTable by using the some java methods. For this, you must have to create a table with some data in the table. Here the table appears on the frame as a graphical format and you get the number of rows and column to its name (Column name) in the command line with appropriate messages.
Description of code:
getColumnCount():
Above method is used for getting the number of columns in the column model
that returns integer type values.
getRowCount():
This method returns integer types value that is number of rows in the model
of table.
Here is the code of program:
import javax.swing.*;
|
Output of program:
![]() |
C:\vinod\Jtable>javac GetRowsAndCols.java C:\vinod\Jtable>java GetRowsAndCols Number of Columns: 3 Number of Rows: 4 Name of column: Emp_name Emp_sal Depart |