aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Strange behavior in interaction between JTable and DefaultTableModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Strange behavior in interaction between JTable and DefaultTableModel" Watch "Strange behavior in interaction between JTable and DefaultTableModel" New topic
Author

Strange behavior in interaction between JTable and DefaultTableModel

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 598
Let me explain my flow step by step
1) I connect to the database as usual
2) I populate the table using my own method updateTable, in this method I use rs2xml.jar to bind the Table Model with the database
3) I create a Table mouse click event, in this event, I copy the values of the model of the current selected row of the table
as shown

4) After that, I have an update button that updates the database and model.fireTableDataChange(); and finally refreshing the table by calling updateTable again
5) Everything goes fine until the table is modified by modifying the text field and clicking on the update button.
6) The table model seems not being changed at all.
7) When I click on the table again, the old value comes up again on the textfields
For example,
When I type "max" to replace "tammie" and press update, the table is updated, when I select back on that record on the table, the textfield is wrong this time.
Any ideas why this behaviour would happen?





http://youtu.be/9danFl_Wz54
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, I think that dumping well over 1,000 lines of code and asking people to find the bug in it is well over the bad behaviour line.

However you said

6) The table model seems not being changed at all.


And I think you're right -- in my quick scan I didn't see any code which was changing the table model.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 598


Okay, I omitted the line, I added it back in
But it doesn't make a difference?
Any further advice please.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I don't see why the presence or absence of that line would make a difference, since it isn't changing the table model in any way. So I think you should continue to look for code which you think is changing the table model and fix it so that it does actually change the table model.

Or if you want serious help with your problem, produce an SSCCE (<== read that link) which people would be willing to look at.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 155
to avoids complicationg simple things

- never to call fireXxxXxx outside of Model, be sure that you have issue with Concurency in Swing, nor for DefaultTableModel, all notifiers are implemented and correctly

- forgot about all code that you wrote, start with a new based on Table From Database by @camickr

- no idea why you held data in List<List<, on bottm (linked code) is model based on List

- all data for JTable are stored in XxxTableModel, use that for only for this reason, JTables view is about preview value came from model, (in this case I don't talking something about editing cell, this will be separate thread)

- split this question to two three separate threads, one about JTable and its view, JTable and view_to_model connection to model and possible Concurency that came from lond and hard JDBC events

- notice you mixing simple array Object[] saveObj = new Object[8]; and List<List< in your model, debug that if returned proper and awaiting value
 
jQuery in Action, 2nd edition
 
subject: Strange behavior in interaction between JTable and DefaultTableModel