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
2010-01-13 18:38:40
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
2010-01-13 18:40:50
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
2010-01-14 10:20:55