在空文本字段中!lblUser.getText().trim().equals("") 在空 jtable 中怎么样?因为我困惑如何捕获空的 jtable
jtextfield 中也有类似的内容...
public void InputUserPass() {
if (!lblUser.getText().trim().equals("") & !txtPass.getPassword().equals("")) {
Login();
} else {
JOptionPane.showMessageDialog(null, "Please fill-up the requirements information before saving.....");
}
}
在 jtable 中怎么样?
请帮助我......提前致谢......
最佳答案
您可以查看它是否有任何数据行:
if (jTable.getRowCount == 0) {
// the JTable jTable is empty
}
如果行数为0,则肯定为空。请注意,这不会测试表是否有行,而是测试行内的单元格为空。为此,您需要获取 JTable 的 TableModel 并迭代行中的每个单元格,检查单元格中的数据,如下所示:
public boolean isTableEmpty(JTable jTable) {
TableModel tableModel = jTable.getModel();
// if model has no rows -- table is empty
if (tableModel.getRowCount == 0) {
return true;
}
// if model has rows, check each cell for non-null data
for (int i = 0; i < tableModel.getRowCount(); i++) {
for(int j = 0; j < tableModel.getColumnCount(); j++) {
if (tableModel.getValueAt(i, j) != null) {
// if any cell has data, then the table is not empty
return false;
}
}
}
// all cells hold null values
return true;
}
关于java - 如何在java netbeans中捕获空jtable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47238695/