• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating JTables

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to see my table update after deleting a row (i.e. the deleted row is still visible). My code seems simple enough:

I did verify that the value of 'rownum' is correct. I am guessing that the problem has to do with when the window manager gets control to actually update the display and that my 'fireTableDataChanged' is pending rather than being ignored. What is not clear is how to give up control so that the window gets updated. When this method ends the only thing that should be happening is that my listners are waiting (menu, selection or sort). What am I missing? TIA.
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What class does tableset belong to? If it's a DefaultTableModel then removeRow should trigger an event that tells the JTable the row was removed. If it's some custom TableModel implementation, you must make sure that the appropriate events are fired. If you extend AbstractTableModel you'd simply need to call fireTableRowsDeleted inside the removeRow method.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. Tableset is indeed a custom TableModel but it does extend AbstractTableModel. Do I understand that I need to override removeRow and include fireTableRowsDeleted in my model?
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you implemented the AbstractTableModel subclass yourself, you don't need to override anything but just change the current implementation. If you extend some other class that defines removeRow, then you should check out if that implementation fires the right events. If not then the method is broken, and you shouldn't override it to fix that - fix the original method itself.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did it, thanks. I was not aware that each type operation used a different fire method. I thought fireTableDataChanged was used for every change.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!