Using all (jComboBox, JTextField, jFileChooser) as table editor overrides the refrences

一个人想着一个人 提交于 2019-11-30 23:09:45

I must admit it took me a while but I found the issue. You have not overridden the DefaultCellEditor.getCellEditorValue() function, which is important for your implementation. This function is called when when the cell being edited loses focus or whatever else causes editing to be complete. Anyway, in your case, it just gets the final value from the last default TableCellEditor (from DefaultCellEditor). This is why the first row keeps getting replaced with the last edited cell value.

Here is a way to fix your problem:

  1. Create a global reference to the comboBox.
  2. Override getCellEditorValue() and return comboBox.getSelectedItem() if the last edited item was the second row. Otherwise, just return super.getCellEditorValue().

This will fix your current issue but your code could use a lot of improvement.

Preliminary examination suggests letting the model notify its listening view of the change:

public void setValueAt(Object value, int row, int column) {
    dataEntries[row][column] = value;
    fireTableCellUpdated(row, column);
}

See also Initial Threads, and consider one of these default directories.

fileChooser = new JFileChooser(System.getProperty("user.dir"));
fileChooser = new JFileChooser(System.getProperty("user.home"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!