This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with setting the cell values in JTable

 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem in JTable.Using the cell renderer and cell editor I have put in a JPanel in my column and the panel contains three comboboxes.It is all working fine...I am able to select values from each of the comboBox.......BUT,the moment I move to the next row the values in all the previous rows are lost.
In my renderer I have just created the panel and I am returning this panel from the getCellRendererComponent.In the celleditor I have created an instance of renderer and I am returning this from the getCellEditorComponent.
I know that for rendering a single JComboBox in a column we can use the DefaultCellEditor(JComboBox c).But what if we want to put a panel(with different components in it) in each cell.
Any suggestions are welcome.
Thanks
Pomchi
 
Matt Robinson
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be putting multiple components in a single cell. I would reevaluate your design. Renderers should be as simple as possible.
------------------
Matthew Robinson co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,
Thanks for your reply.I also thought that it is complicated to put more than one component in a cell.So I have solved this problem by putting a common header for those three related cells.(In one cell I wanted to put three combo boxes each for selecting month,day and year and now I have a common header called date under which I have three columns).
Now I just have one component in each cell.
Using DefaultCellEditor(JComboBox c) all my cells are working fine and all the values are also getting selected.
But when I use my own renderer and editor for putting a single component JComboBox in the cells, the problem still persists.I will get the combobox in my cell,I will be able to select a value from the combobox but when I will move to the next cell in the same column the first value that I had selected will get lost.
I know that I need to do something in my celleditor but I don't know what.
Thanks again for your response and any suggestion would help.
-Pomchi
 
Matt Robinson
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like your table model data is not getting updated properly. Can you post sample code that demonstrates this?
Thanks,
-Matt
------------------
Matthew Robinson co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe
 
mick barry
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using your own tanble model check that you have implemented the setValueAt method correctly.
This methods needs to update your model data and fire appropriate events.

------------------
-------------------------
http://www.objects.com.au
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt and Mick,
Thanks for your reply.
Here is my code for the table model


Still I want to clarify this again that in my renderer I have created an instance of JCombobox and in getCellRendererComponent I say return this.In cell editor I have created an instance of my renderer and in getCellEditorComponent I just say return renderer.I am not doing anything else in the editor or renderer.
I don't know much about tables.This is my first table.So any sample code for inserting a JComboBox in the cells using our own renderer and editor would be very helpful.
Thanks
Pomchi
[This message has been edited by Pomchi Bedi (edited May 04, 2001).]
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is it a very DUMB question that nobody is giving any reply.Even if it is please respond and help.
Thanks
Pomchi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic