Unlike most data structures, JTable
does not have isEmpty()
method. So how can we know if a given JTable
doesn't contain any value?
A JTable will generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener and RowSorterListener interfaces. We can validate whether the JTable cell is empty or not by implementing the getValueAt () method of JTable class.
So,my opinion is that if we cant check the jTable,check the Dataset which be written in the table. Share Improve this answer Follow edited Dec 25, 2017 at 5:49 answered Dec 22, 2017 at 11:25 BabafingoBabafingo 122 bronze badges 3 (1-) this code shows how to add data from a ResultSet to a table model.
A JTable is a subclass of JComponent class for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable will generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener and RowSorterListener interfaces.
setValueAt (Object value, int row, int col) : Sets the cell value as ‘value’ for the position row, col in the JTable. Below is the program to illustrate the various methods of JTable:
This will return actual number of rows, irrespective of any filters on table.
int count= jTable.getModel().getRowCount();
jTable.getRowCount()
will return only visible row count. So to check isEmpty() then it's better to use getRowCount()
on model.
public static boolean isEmpty(JTable jTable) {
if (jTable != null && jTable.getModel() != null) {
return jTable.getModel().getRowCount()<=0?true:false;
}
return false;
}
table.getRowCount();
table.getColumnCount();
If either one is 0, then there is no data.
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