tags:

views:

417

answers:

1

Hello,

I am working with Java. I have created a JTable, and I have made the cells of the table editable. My problem is that when I select a cell and write a value in it, and then click Enter, the value, which I have typed does not stay in the cell where I have typed it, but jumps in another cell somewhere in the table. The value stays the same, but on it the cell, which I have typed it.

I represent the cells of the table as instances of class Cell.

Something happens by default, and I don't know what to change in order to make the value of the cell stays in the cell, though I looked through some materials online about JTables. Do you know what the problem might be, and where should I look in the code in order to fix it? Thank you in advance.

+1  A: 

It looks like your model indexes are being confused somewhere.

If you are using a RowSorter at all, then JTable.getSelectedRow will return the index of the row being viewed, not the row in the model. You can use RowSorter.convertRowIndexToModel() to get the correct index.

Double check your JTableModel.setValueAt() method to make sure the cell indexes are the ones you have edited, and that you're storing the new value in the right place.

Cogsy