0
我试图制作一个JTable,它有一个单元格中的JComboBox。我知道我可以使用celleditor,但诀窍是我需要每行的组合框中有不同的信息。表中的每一行代表一个对象,在那个对象上有一个数组列表,它是我想要的组合列表中的数组列表的内容。这是我迄今为止的思考过程。JTable和JComboBox的组合使用
table = new JTable(tableModel);
tableModel = new DefaultTableModel();
forestTable.setModel(tableModelForest);
tmpColum = forestTable.getColumnModel().getColumn(5);
tmpColum.setCellEditor(new DefaultCellEditor(comboBox));
comboBox = new JComboBox<Tree>();
comboBox.setEditable(false);
现在,当我后来调用该方法(通过按下一个按钮),我想插入新行与明杆中的5独特的组合框,但我不知道怎么做。我尝试过。
public void fillTable(String text){
tableModel.insertRow(tableModel.getRowCount(), "" });
tableModel.fireTableRowsInserted(
tableModel.getRowCount(),
tableModel.getRowCount());
comboBox.addItem(text);
}
的输入是fillTable是字符串,因为它似乎更容易给串的例子indput代替阵列 – 2013-03-06 10:17:38
使用一个'ComboBoxCellEditor',当'getTableCellEditorComponent'被调用时,检查该行的索引并重新加载' ComboBoxModel' – MadProgrammer 2013-03-06 10:35:56
This [Example](http://stackoverflow.com/questions/13699467/add-different-combobox-for-each-row-of-a-column-in-a-jtable/13703143#13703143)解决了你的问题问题。 – Amarnath 2013-03-06 19:00:27