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

TableModel question

 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am instantiating a new TableModel and a new JTable in the constructor of GUI class. Obviously, at this time there is nothing to display in the JTable and so, the instance variable in the TableModel that holds actual data is null. When user actually does a search, I know what to display in the JTable and I set the instance variable in the TableModel to search results and call setModel method on JTable to refresh the data. But now at run time I get null pointer exception.
Is there a way to dynamically change model contents depending on search results, so that I can avoid instantiating a new TableModel everytime a new search is done.
Thanks in advance.
 
Eric Li
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use just one single TableModel for this assignment. Whenever you want to refresh JTable with new table values, you pass them to a method in your TableModel. Inside that method, you will change the TableModel's values to the new table values. Right after this, call the fireTableChanged(new TableModelEvent(this)). This should do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic