Putting JComboBox into JTable

Extend JTable with this code:

@Override
public TableCellEditor getCellEditor(int row, int column) {
   Object value = super.getValueAt(row, column);
   if(value != null) {
      if(value instanceof JComboBox) {
           return new DefaultCellEditor((JComboBox)value);
      }
            return getDefaultEditor(value.getClass());
   }
   return super.getCellEditor(row, column);
}

This will create a unique JComboBox cell editor for each combo box you get the a value for.

Leave a Comment