• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable: Get Row Index By Column(s) Value(s)

 
Jillian Kay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a JTable with hundreds+ of rows of data. The user is able to move the columns and rows around, and delete/add rows and columns at will. The user cannot change the data, but individual cells are constantly updating from an outside source.

I need to be able to get the row index where columnA="x" and columnB="y"...and then update that one individual cell.

(for example, find the row where FirstName = "Jane", LastName ="Doe" and update the PointsEarned column.)

Is there anything built in to the default table model to do this? Since this table could update very very often, I need something relatively quick.

Any suggestions would be GREATLY appreciated!
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing built in.
You're going to want to search your TableModel. You could write a TableModel that indexes it's rows by column value. That would make searching very quick.

Personally though, I would go for the simple solution. 100 rows is really not very many at all. Just search your TableModel for the required values. If it turns out to be not fast enoguh you can optimise it later.

hth, D.
 
Jillian Kay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,I think that second answer is what I settled on yesterday, and you're right, if it isn't fast enough I can always go back and make that "find" method faster somehow.

Thanks for your advice! -Jillian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic