Hi!
I have a jtable object, and I am trying to test the object to see if it
has been left blank (i.e. "" or null).
So I tried
getValueAt(iRow, iCol) == "" and getValueAt(iRow, iCol) == null
and neither seem to work, but both do compile correctly.
So my question is.... How do I test a jtable's cell for a blank entry?
Many Thanks.
zero - 03 Jan 2006 17:59 GMT
"tiewknvc9" <aotemp@hotmail.com> wrote in news:1136310568.610455.47510
@g49g2000cwa.googlegroups.com:
> Hi!
>
[quoted text clipped - 10 lines]
>
> Many Thanks.
I haven't tested, but I think this would work - if you fill the JTable
with Strings. You may need a specific approach based on what objects are
in the JTable.
If you fill the table with for example HashMaps (I can't immediately
think of a reason why you would want to do that, but it's quite
possible), you could use something like:
Object o = getValueAt(iRow, iCol);
if(o != null)
if(o instanceof HashMap)
return ((HashMap)).isEmpty();
return false;
A more or less generic (not to be confused with Java's generics) way
could be:
getValueAt(iRow, iCol).toString().equals("")
Always make sure you test for null first of course, to avoid
NullPointerExceptions.

Signature
Beware the False Authority Syndrome
Vova Reznik - 03 Jan 2006 18:01 GMT
> Hi!
>
[quoted text clipped - 10 lines]
>
> Many Thanks.
Object value = getValueAt(row, col);
if(value == null || ((value instanceof String)&&
((String)value).length == 0)){
// null or if String then it is empty
}
Result of using an operator [==] and a method [equals] may not be always
the same.
tiewknvc9 - 03 Jan 2006 19:26 GMT
I followed Vova's advice, it worked like a charm.
Thanks