This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable doesn't refresh after booking record

 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the JTABle i use an AbstractTableModel when booking i update the datafile.
That works just fine.
But the JTable doesn't show the new results only when i exit and restart the application.
In my update method i call :

This worked at first but now it doesn't seem to work anymore...
Can someone give a clue?
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Theo, if you are using TableModel, try fireTableDataChanged(). Or you can just create a new JTable in the update too. Either way, table will be updated.
GoodLuck.
 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in the update of my AbstractTableModel i call the fireTableDataChanged()
and the notifyObservers calls the update()....
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Theo
Originally posted by Theo van Loon:
But in the update of my AbstractTableModel i call the fireTableDataChanged()
and the notifyObservers calls the update()....

Here's how I did. In the controller, whenever you search with new criteria the results from the backend are returned in a arraylist or something like that right? What I did is used a function called setResult in TableModel subclass. In the controller I call this method of TableModel with the new arraylist and then invoke fireTableDataChanged. It worked fine.
 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satish Avadhanam:
Hi Theo

Here's how I did. In the controller, whenever you search with new criteria the results from the backend are returned in a arraylist or something like that right? What I did is used a function called setResult in TableModel subclass. In the controller I call this method of TableModel with the new arraylist and then invoke fireTableDataChanged. It worked fine.

Satish thanks for the help!!
This is the code :

Can i safely say that when an exception occurs in my book method it will never update the tablemodel?
Thanks a lot!!
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Theo
Originally posted by Theo van Loon:

Can i safely say that when an exception occurs in my book method it will never update the tablemodel?

As such from the above code, if an exception occurs at dataAccess.book(..) method, the next line will not execute and so the tablemodel will not be updated in my understanding.

Thanks a lot!!

Here's the flow in my controller class which updates the table.

This will update the table. Also you can use something like this instead of above two lines.

Good Luck.
 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satish last one :
do you call fireTableDataChanged() in the controller class or can you also call this in the update method of the TableModel class :

Thanks!!
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact I think this method is preferred, controller tells teh model to change it's data. Model tells registered listeners that are interested in that data that it's changed.
What would happen if you had more complicated logic in the model that may decide not to update the views (if, for example the data is the same). In the controller it MUST always call the update, but if this is from the model then it can process the data and decide.
Steve
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Theo, sorry if I was'nt clear before. I called fireTableDataChanged() in the controller only. It seems that you are calling them in the TableModel method. I don't know if it works or not, but I called it from the controller itself.
If you want to follow the second approach here's what I did.

Good Luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic