Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > jtable's getvalueat...

Reply
Thread Tools

jtable's getvalueat...

 
 
tiewknvc9
Guest
Posts: n/a
 
      01-03-2006
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.

 
Reply With Quote
 
 
 
 
zero
Guest
Posts: n/a
 
      01-03-2006
"tiewknvc9" <(E-Mail Removed)> wrote in news:1136310568.610455.47510
@g49g2000cwa.googlegroups.com:

> 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.
>
>


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.

--
Beware the False Authority Syndrome
 
Reply With Quote
 
 
 
 
Vova Reznik
Guest
Posts: n/a
 
      01-03-2006
tiewknvc9 wrote:
> 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.
>


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.
 
Reply With Quote
 
tiewknvc9
Guest
Posts: n/a
 
      01-03-2006
I followed Vova's advice, it worked like a charm.

Thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments