fireTableDataChanged JTable focus problem

Hi,

I'm sure there must be a solution to this. I have a JTable and Custom AbtractTableModel. The model holds "current download data" and is updated every second by way of fireTableDataChanged().

The problem is that any selected rows are then unselected after the update, which is no good as i cant perform tasks on selected rows.

Any Ideas?

[367 byte] By [jaysona] at [2007-11-27 8:51:49]
# 1

Before calling the update save the selected row in another variable and then use: -

jTable.changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)

Check the API docs for the variable descriptions

c0demonk3ya at 2007-7-12 21:05:50 > top of Java-index,Desktop,Core GUI APIs...
# 2
yeah thought as much, thank you :)
jaysona at 2007-7-12 21:05:50 > top of Java-index,Desktop,Core GUI APIs...
# 3
> and is updated every second by way of fireTableDataChanged(). This updates the entire table. Do you change the entire table or only certain cells. If you only update certain cells then you should fire the appropriate method and you won't lose selection.
camickra at 2007-7-12 21:05:50 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks, one more quick question, im using the TableSorter class that can be found in the java tutorials. Does this alter the indicies of objects in a table when sorted differently?
jaysona at 2007-7-12 21:05:50 > top of Java-index,Desktop,Core GUI APIs...
# 5

> Thanks, one more quick question, im using the

> TableSorter class that can be found in the java

> tutorials. Does this alter the indicies of objects in

> a table when sorted differently?

Basically the TableSorter class sits between the JTable and the TableModel.

The indices in the tablemodel don't change but the order in which the indices are displayed do (if that makes sense)

If you check the TableSorter class you should find some methods which will give you the index of the row in the model when supplied with the index of the selected row in the table.

So if you need to get the index of an item in the table model then you need to get the selected row from the table, run it through the method of the TableSorter to give you the equivalent index of the model.

c0demonk3ya at 2007-7-12 21:05:50 > top of Java-index,Desktop,Core GUI APIs...