Search code examples
javaswingjtable

How do I change view index based selection in JTable to model index based selection?


By default, the selection of rows in a JTable uses view index. View index-based selection means that selection of rows in a table is associated with the row number instead of the actual data that is selected. Is there any way to change this so that selection is based on the model so that the data I select is associated with the selection?


Solution

  • You probably can't change the behaviour, but you can use some of JTables methods to convert between the two:

    • int convertColumnIndexToModel(int viewColumnIndex)
    • int convertColumnIndexToView(int modelColumnIndex)
    • int convertRowIndexToModel(int viewRowIndex)
    • int convertRowIndexToView(int modelRowIndex)