与大多数数据结构不同,JTable没有isEmpty()方法.那么我们怎么知道给定的JTable不包含任何值?
table.getRowCount();
table.getColumnCount();
Run Code Online (Sandbox Code Playgroud)
如果任何一个为0,则没有数据.
这将返回实际的行数,而与表上的任何过滤器无关。
int count= jTable.getModel().getRowCount();
Run Code Online (Sandbox Code Playgroud)
jTable.getRowCount()将仅返回可见的行数。因此,要检查isEmpty(),最好getRowCount()在模型上使用。
public static boolean isEmpty(JTable jTable) {
if (jTable != null && jTable.getModel() != null) {
return jTable.getModel().getRowCount()<=0?true:false;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8485 次 |
| 最近记录: |