tags:

views:

178

answers:

2

I am trying to add JComponents to JTable Cells. Do I Implement CellRenderer or CellEditor?

+4  A: 

What you need is a custom editor which will return the JComboBox (or whatever component you want to use). You should check the Sun tutorial for JTable, it contains an example on how to use a JComboBox as an editor. If you want to use JComboBox as a renderer as well, the tutorial applies to that too.

Carlos
yep, just keep in mind that renderer is for display and editor is for when editing a cell. You may only need to implement Editor :)
Arthur Thomas
A: 

You could also do it with the DefaultCellEditor by passing in an instance of a JComboBox (or JCheckBox or JTextField) to the constructor.

willcodejavaforfood