我在我的应用程序中为我的JTable写了一个AbstractTableModel。我从教程中看到,我可以通过获取列模型然后使用特定列来使列具有组合框,例如:
TableColumn sportColumn = table.getColumnModel().getColumn(2);
...
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Chasing toddlers");
comboBox.addItem("Speed reading");
comboBox.addItem("Teaching high school");
comboBox.addItem("None");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
但是我如何针对特定细胞或行进行此操作?
答案 0 :(得分:3)
JTable的默认实现是基于列的。如果您想要基于行或单个单元格的选择,更改该行为的唯一方法是创建JTable
的子类并覆盖方法public TableCellEditor getCellEditor(int row, int column)
。在您的实现中,您可以使用提供的行和列索引进行不同的选择。 JTable将始终使用此方法来获取单元格编辑器。
答案 1 :(得分:2)