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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with setting the cell values in JTable" Watch "Problem with setting the cell values in JTable" New topic
Author

Problem with setting the cell values in JTable

Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
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

Joined: Apr 30, 2001
Posts: 28
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


Matthew Robinson<BR>matt@mattrobinson.com<BR>co-author of "<a href=http://www.amazon.com/exec/obidos/ASIN/189311578X/ref=ase_electricporkchop/107-7882751-0234939 target=newwindow rel="nofollow">Swing</a>" (1999, Manning Publications). Freely available at <A HREF="http://www.spindoczine.com/sbe" TARGET=_blank rel="nofollow">http://www.spindoczine.com/sbe</A>
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
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

Joined: Apr 30, 2001
Posts: 28
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

Joined: Apr 30, 2001
Posts: 16
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


-------------------------<BR>http://www.objects.com.au
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
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

Joined: Apr 03, 2001
Posts: 55

Is it a very DUMB question that nobody is giving any reply.Even if it is please respond and help.
Thanks
Pomchi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with setting the cell values in JTable