Putting JComboBox into JTable

前端 未结 9 1276
离开以前
离开以前 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:47

    You need to override:

    Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    

    ...in TableCellEditor. The value passed in to this method is what you can put in your JComboBox. That means that the 'value' for that particular cell needs to be something that can be translated into a collection. It could potentially just be a List of objects or it could be a POJO with fields that could be made into a JComboBox.

    So just edit MyComboBoxEditor to override that method and change your model to allow for an Object that actually represents several other objects.

提交回复
热议问题