如何签到jTable
我试图从 jField
添加的值存在与否?我正在使用 Vector<Object>
在 jTable
.
最佳答案
应该这样做。
public boolean existsInTable(JTable table, Object[] entry) {
// Get row and column count
int rowCount = table.getRowCount();
int colCount = table.getColumnCount();
// Get Current Table Entry
String curEntry = "";
for (Object o : entry) {
String e = o.toString();
curEntry = curEntry + " " + e;
}
// Check against all entries
for (int i = 0; i < rowCount; i++) {
String rowEntry = "";
for (int j = 0; j < colCount; j++)
rowEntry = rowEntry + " " + table.getValueAt(i, j).toString();
if (rowEntry.equalsIgnoreCase(curEntry)) {
return true;
}
}
return false;
}
关于java - 如何检查我要添加的 jTable 中是否存在值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15639611/