如何知道JTable是否为空? [英] How to know if a JTable is empty?

查看:105
本文介绍了如何知道JTable是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与大多数数据结构不同,JTable没有isEmpty()方法.那么我们怎么知道给定的JTable是否不包含任何值?

Unlike most data structures, JTable does not have isEmpty() method. So how can we know if a given JTable doesn't contain any value?

推荐答案

这将返回实际的行数,而与表上的任何过滤器无关.

This will return actual number of rows, irrespective of any filters on table.

int count= jTable.getModel().getRowCount(); 

jTable.getRowCount()将仅返回可见的行数.因此,要检查isEmpty(),最好在模型上使用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;
    }

这篇关于如何知道JTable是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆