This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Deleting a JTable Row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Deleting a JTable Row" Watch "Deleting a JTable Row" New topic

Deleting a JTable Row

Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 210
I am on to the next layer of the onion, namely deleting rows from a JTable. I figured out the hard way that having sortable columns requires I use convertRowIndexTableToModel to get the proper index for the selected row(s). After going through all the machinations associated with deleting the selected row(s), I need to actually remove them from the JTable itself. It is not clear what I need to do to do that (other than I need to delete high to low indexes). By the time I reach that point the original selection has been converted so do I need to call some (currently unknown) function to covert back or do I use the converted row index and should I have saved the unconverted index(s)? Also does the converted row index take into account a zero base or do I need to subtract 1? I did get an out of range exception using the converted row index. It was 1 greater than the max according to the trace back. TIA.
Veena Nair

Joined: Jul 08, 2012
Posts: 13
i didn understand your question properly.. But from what i understood you are trying to delete few rows after having performed "convertRowIndexToModel()" opearation..
So, having performed the convertion to "Table Model " now indices of the underlying data would have been changed(if you have performed some sort of re_arrangement)... & the view as well as the real arrangement will also be the same... Thus you can delete it as such.. The original rows which you selected will only be deleted...!
Im also a beginner in Swings..! & im not at all sure about my comment ..! ... !
Now Lets wait for some Expert Answers..!!
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 210
I found part of my answer. There is an opposite function called convertRowIndexToView. However, it is still not clear which I should use.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 210
I had to rethink my logic for deleting what I needed from the table and had to change my logic so this question is now moot. I have a related but different question so I'll start a new thread. Thanks.
Consider Paul's rocket mass heater.
subject: Deleting a JTable Row
Similar Threads
JTable & Edit Button Click
Dynamic JTable