• Post Reply Bookmark Topic Watch Topic
  • New Topic

I have a problem with a JTable that is driving me mad!

 
Sethuraman Ramasubramanian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me explain the full problem below:
1. I have a JFrame
2. Within the JFrame I have a Tabbed Pane
3. Within the tabbed pane I have added a JPanel.
4. Within the JPanel I have a JTable within a JScrollPane.
5. I have a model for the JTable that extends AbstractTableModel
6. I have a reset button for the JTable that should 'reset' all edits done on that table with the original data.
7. The painful thing is the reset does not work! I am pretty sure I have updated the model with the old data. I feel it just doesn't reflect on the view. The minute I update the model with new data, I fire a fireTableDataChanged();. The info I got from the internet say that that should do. Is that true?

The code as below:

The reset button code on the JPanel is as below:



The table model code is as below, the reset method is the last method.





Can you tell me what I am doing wrong! Thanks a lot for your help.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are cloning player details in constructor then getRowCount() should return playerList.size()
instead of teamDetails.getPlayerDetails().size() even if the size of them is the same.

savePlayerInfo() is incorrect you can't set values like that, use setters of the Vector.

And teamDetails.getPlayerDetails().clone() should return the orginal data if you haven't
modified it elsewhere.
 
Sethuraman Ramasubramanian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mikko,

Thanks for your response

Mikko Kohtamäki wrote:if you are cloning player details in constructor then getRowCount() should return playerList.size()
instead of teamDetails.getPlayerDetails().size() even if the size of them is the same.


Nice catch, I must have been coding late in the night.. Need to change that to playerList.size().


savePlayerInfo() is incorrect you can't set values like that, use setters of the Vector.


I am not sure why you say this. If I do what I have done, the 2 iterators will land up having contents that refer to the same objects... I have effectively searched and replaced the old iterator's contents with the new iterators' . As you would have seen from the code, I just need reorder the new iterator's contents based on the old iterator. Can you say why this wont work?


Further, could you answer the orignial question, why is my view not reflecting the changes done to the model. I am more concerned with the reset method and why that doesn't work...

Thanks
Sethu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!