I am unable to add a Combo box in JTable 2nd column of each row with different value. Please help me.. I already try lots of time with many example but I man unable to change the ComboBox value in every row. Is it possible to rander a particular column with different component in every row ?
TableCellRenderer.getTableCellEditorComponent takes both the row and column numbers, so you can use that to your advantage. For example:
Of course you can use a Collection or List instead of an Object[], but the principle is the same.
Thanks Rob Prime. It is working fine.
yours solution helps me a lot.
I have one more doubt that , can not we Render the same cell with different component. Like the same column in first row with JCombo Box and the same column in next row with JTextField.
I have a Map, which I have to display in n-rows and 3-column table ... where for rew columns the value need to select from combobox and few need to enter. The number of rows we cant define... because it is dynamic.
I face one more problem that, when i click on Cell for edit,then the scope is remains their till i will not give enter , in the case of JTextField.
Similarly in JComboBox the Scope is remain there till if I will not select any value from JComboBox.
Is there any way that it will lose its scope when i will click on any other cell.
Instead of putting all the code in a custom editor, override the getCellEditor(...) method of JTable to return the appropriate editor for the row and column.
Rob Camick wrote:Instead of putting all the code in a custom editor, override the getCellEditor(...) method of JTable to return the appropriate editor for the row and column.
Uhm yeah, that would be better
Rob means this (which I used myself for a similar situation as well... why did I forget?):