Putting JComboBox into JTable

前端 未结 9 1283
离开以前
离开以前 2020-11-30 10:22

I want to put individual JComboBoxes into each cells of a JTable. ie. The JComboBox content is not identical for each cell.

I basically would like to be able to jus

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 10:48

    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.

提交回复
热议问题