jtable's getvalueat...

T

tiewknvc9

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

zero

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

Vova Reznik

tiewknvc9 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top