【发布时间】:2009-01-19 16:05:25
【问题描述】:
我正在寻找previous question 的答案,并且有一个巧妙的想法来克服JTable 的限制。我需要编辑器逐行不同,而JTable 只能为每一列处理一个编辑器。
所以我的想法是使用MouseListener 来检查JTable 上的行和列,并每次设置新的编辑器。
但是,第二次调用setCellEditor() 没有任何效果。编辑器仍然是第一个设置的。那么如何让“setCellEditor”为同一列再次工作?
这是MouseListener中的代码。
public void mouseClicked(MouseEvent e) {
int cols = resultTable.columnAtPoint(new Point(e.getX(), e.getY()));
int rows = resultTable.rowAtPoint(new Point(e.getX(), e.getY()));
StorageObject item = (StorageObject) resultTable.getModel().getValueAt(rows, cols);
TableColumn col = resultTable.getColumnModel().getColumn(cols);
col.setCellEditor(new MyComboBoxEditor(item.list));
}
【问题讨论】: