File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JTable remove rows trouble. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JTable remove rows trouble." Watch "JTable remove rows trouble." New topic

JTable remove rows trouble.

Antonio Vieira

Joined: Jul 11, 2005
Posts: 7
Hi everyone

I've been trying to delete a row from my JTable without complete success. My problem is that while the row is removed from both the model and the view, the view is showing the wrong value. Here are the steps to reproduce my issue:

1. Display a single row in a JTable with all cells populated with data.
2. Click a button which adds a new row to the JTable's model.
3. A new empty row is displayed at index 0 and the existing row is positioned at index 1.
4. Enter data into a cell in the new row and keep focus in that cell.
5. Click a button which removes the row at index 0.
6. The new row is removed from the model and the view, but the existing row's column now takes on the value of the removed row's edited cell.

Below is the relevent code:

I'm not sure of what else I need to be doing here in order to get this working. Do I need to implement TableChangeListener and deal perform so magic there?

Any help provided is appreciated as always.

Thomas Paul Bigbee
Ranch Hand

Joined: Jun 28, 2005
Posts: 71

I don't edit cells, I specifically extended the class to disallow

* Class that extends the DefaultTaleModel to allow no editing of the row
* cells.
* @see - DetaultTableModel
class UndeitableDefaultTableModel extends DefaultTableModel {...

however, hopefully the below will point you in the right direction

Antonio Vieira

Joined: Jul 11, 2005
Posts: 7
Hi Tom

Thanks for the reply.

I take it then that you are receiving user input through some other means such as an input dialog.

My design will allow (try to allow) for the editing of the JTable data directly. The behaviour I've described is pretty strange. What do you think the cause of this "weirdness" is?

Also, I've noticed that you've extended the DefaultTableModel rather than AbstractTableModel. I was under the impression that extensions should be derived from abstract implementation and not the concrete. What made you arrive at that decision?

Thanks again for your help.

I agree. Here's the link:
subject: JTable remove rows trouble.
jQuery in Action, 3rd edition