• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JTable remove rows trouble.

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic