Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems displaying values in JTable

 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a custom JTable that has a custom cell renderer for each cell. I get the table to display the right component for each cell, but for some reason the actual values of each cell are not displaying. If the cell is editable, the first time I type something, the value that was in the cell suddenly appears, if I move focus, it disappears. If I type something else the value is replaced, move focus, the value disappears again. If I click on the cell and start typing again, the value I typed before shows up along with the values I type. But again, the values disappear once I leave the cell. The component for this cell is a custom JTextField.
If anybody has any idea of what might be going on here, please please help! I am running out of ideas. I must be overlooking something obvious, and I'm hoping somebody can point what that is
Thanks,
Sayuri
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about supplying code for your renderer.
 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
Thanks for replying. I am not following what you mean by "supply code to renderer".
My renderer subclasses from DefaultCellRenderer and overrides the getTableCellRendererComponent(..) method which is currently returning the correct component. It also has a method to return the editor for the given component.
What other code is there to supply? Could you please be more specific?
Thank you,
Sayuri
 
kate damond
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post the code you have used for your renderer, to this form so we can have a look and see if you've made a mistake
Kate
 
Swamy Vatti
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is because u dont have the implementation for the method setValueAt of TableModel.
Implement this method and I guess you should not be having any problems
 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented the setValueAt in the table model, and I know it is setting the value, because when I enter the cell and type something, the value that was set and what I typed shows up.
The problem is that the value only shows up when you enter the cell and change it. As soon as you leave the cell, the value is no longer displayed.
Thank you all for replying, it is helping me eliminate all the possible things that could have gone wrong
Originally posted by Swamy Vatti:
Hi,
This is because u dont have the implementation for the method setValueAt of TableModel.
Implement this method and I guess you should not be having any problems

 
Swamy Vatti
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I guess the renderer is not picking up the value from the model.
In the getTableCellRendererComponent(Object value,....)
set the components text to the 'value' from the parameter.
ie TextField.setText(value.toString());
 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swamy,
Thanks a lot, you've made my day! I knew it was something obvious, just couldn't put my finger on it. Thanks again for your input. It would be my luck that for the cells that I was testing which was using the custom textfields, the value was not being set. I just validated Murphy's Law
Sayuri
Originally posted by Swamy Vatti:
Then I guess the renderer is not picking up the value from the model.
In the getTableCellRendererComponent(Object value,....)
set the components text to the 'value' from the parameter.
ie TextField.setText(value.toString());

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic