Re: moving (JTable) columns



> I'd like the operator to be able to move the columns while data is being
> filled, but problems occur as the data
> is sent to the column where the data was (prior to a move).
>
> So if I have 2 columns with the 1st column header lastname and the 2nd
> column being a boolean checkbox with header brown eyes (true or false),
> when I switch the 2 columns, column 2 cell data SHOULD be lastname and
> column one SHOULD be checkbox (true or false), but its just the opposite
> (prior to column movement).

I'm pretty sure that you have mixed up view indexes and model indexes.

View index is zero based index, indicating column ordering. So this index is
0..N-1 (where N is number of columns). TableColumnModel of table maintains
this view index array. Whenever columns are reordered view indexes of
columns will change.

Model index is index of column in the table model. This index is just some
integer, so that each column have unique number. I.e. there is nothing
requiring these indexes to be zero based.

Model data must be always accessed using model index, thus view index must
be converted into model index when needed. JTable contains necessary
conversion methods for converting between these two indexes.


--
KI -- http://kari.world.dy.fi
.