Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

fireTableDataChanged() is not working  RSS feed

 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I found an interesting example HERE and i made some modification in the table model to use the second column (with the checkbox).

The data that i put in that column are from a database column. The problem is when i want to reload the table the (fireTableDataChanged() is not working).


When i start the app the table loads the data but when i want to add or remove it doesnt refresh.

- the query is sent to the database but the table did not repaint.

Please tell me what i am missing

Here is what i modify

 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to your code the loadTable() method is called in the constructor of the DataModel class, but you never create an object of that class. So that would mean the loadTable() method is never called.

However I'm sure your actual code does create a DataModel object, it's just that you didn't post that part of the code. Which isn't very helpful, really. However let me suggest this: when you call fireTableDataChanged it notifies all of the listeners of the DataModel to redraw themselves. But there can't be any listeners because you're only just constructing the object and haven't got around to assigning listeners yet. So let's have a look at the code where you create DataModel objects.
 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad i didnt post the rest of the code where the datamodel object is created.





and there is a button which is sending data to DB then i was tryingf to call



i was trying also to recall the loadTabel method but didnt work



 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally when you want to provide an entirely new set of data to a JTable, you simply create a new TableModel and call "theJTable.setModel(theTableModel)". Why don't you just do that? It's a lot simpler than trying to do what you're doing.
 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried in the button action listener



but it now it trows an exception



what i missed?

 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul Clapham for the reply.

I figured out what the problem was that i needed to created the value object each time the loadTable() is called



then just use the model.loadTable() and everything is working fine

Cheers!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!