Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add more than one component to a cell in JTable  RSS feed

 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to add three components (three comboBoxes for date) to a cell in a JTable. Can somebody help me with any such example.
Thanks
Pomchi
 
John Zukowski
Author
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add three components to a container. Add container.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
Thanks for the prompt reply.
This is exactly what I tried writing my own renderer and editor.It works fine and I am able to select values from each of the combobox as well,but the moment I move to the next cell in the same column the value that I had selected in the first cell is gone.The value that I select is not getting set in the cells.
I tried doing various things but nothing seems to work.
It is very important for me so any sample code or any suggestion is highly appreciated.
Thanks
Pomchi

 
Aleksey Matiychenko
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Renderes only display data. In order to edit the data you need to user CellEditor as well.
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Aleksey....I have used the cell editor because of this editor I am able to select the values from all comboBoxes in one cell but the values are not staying.
In my renderer I have created a panel in which I have added three ComboBoxes and in getCellRendererComponent I am returning this panel.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 guess I need to do something more in the cell editor but I don't know what.
Please suggest what is going wrong here.(I have really tried a lot of things but nothing is working so any code sample for rendering and editing a single component will also help.)
Thanks
Pomchi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!