我正在使用JComboBox
作为JTable
的单元格编辑器。当我从ComboBox的下拉列表中选择值之一时,不会调用setValueAt
。我知道这一点是因为我已经覆盖了该功能。基于在此单元格中选择的值,同一表的另一个单元格中的值是固定的。另外,我需要知道此事件的actionListener
是什么,即当我更改ComboBox中的值时。
仅当焦点更改为表中的另一个单元格时,才会调用setValueAt
,仅单击表的外部也无济于事。
@Override
public void setValueAt(Object o,int row,int col)
{
super.setValueAt(o, row, col);
if(((String)o).matches("1"))
{
super.setValueAt(o, col-1, row+1);
return;
}
if(((String)o).contains("/"))
super.setValueAt(((String)o).substring(2), col-1, row+1);
else
super.setValueAt("1/"+(String)o, col-1, row+1);
}
最佳答案
我才找到路...
我需要将actionListener添加到作为CellEditor类成员创建的JComboBox组件中,并在侦听器函数中,我需要调用stopCellEditing以便调用setValueAt ...
关于java - 在JTable中使用JComboBox作为单元格编辑器并保存更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9707985/