Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes JTable: Get Row Index By Column(s) Value(s) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable: Get Row Index By Column(s) Value(s)" Watch "JTable: Get Row Index By Column(s) Value(s)" New topic
Author

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

Jillian Kay
Greenhorn

Joined: Apr 02, 2004
Posts: 5
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!


Lost, as always.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
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

Joined: Apr 02, 2004
Posts: 5
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
 
Consider Paul's rocket mass heater.
 
subject: JTable: Get Row Index By Column(s) Value(s)