Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

jtable's getvalueat...

Thread view: 
tiewknvc9 - 03 Jan 2006 17:49 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.