I want to select a value in a default cell editor combobox initially. When i set that inside renderer or editor the combo always shows the same value even if the user changes it, since i am setting the value in renderer. How to set the combobox value in renderer and allow the user to make changes to the combo? below is my code:
public TableCellRenderer getCellRenderer(int row, final int column) {
if (column == 1) {
TableCellRenderer renderer = new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable arg0, Object arg1,boolean arg2, boolean arg3, int row, int col) {
String text="";
Component comp;
if(lovArray[row]!=null && lovArray[row].split("\\|").length>1)
{
JComboBox combo = new JComboBox(lovArray[row].split("\\|"));
comp =combo;
//combo.setSelectedItem(values[row]);
}
else
{
comp = CustomTable.super.getCellRenderer(row, col).getTableCellRendererComponent(arg0, arg1, arg2, arg3, row, col);
}
return comp;
}
};
return renderer;
}
return super.getCellRenderer(row, column);
}
in the above code i am going to display a combo only if the values for that particular row has multiple values delimited by "|". otherwise am going to return the default renderer.
I also want to set the combo value to a particular value from an array. but since am setting inside renderer its always displayng the same value even if the user changes the combo value. how to fix this?