aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problems displaying values in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problems displaying values in JTable" Watch "problems displaying values in JTable" New topic
Author

problems displaying values in JTable

Sayuri Coppinger
Greenhorn

Joined: Jun 06, 2001
Posts: 20
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

Joined: May 17, 2001
Posts: 2823
How about supplying code for your renderer.
Sayuri Coppinger
Greenhorn

Joined: Jun 06, 2001
Posts: 20
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

Joined: Apr 17, 2001
Posts: 77
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

Joined: May 02, 2001
Posts: 57
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
Sayuri Coppinger
Greenhorn

Joined: Jun 06, 2001
Posts: 20
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

Joined: May 02, 2001
Posts: 57
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

Joined: Jun 06, 2001
Posts: 20
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());

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problems displaying values in JTable