Correctly getting data from a (sorted) JTable

后端 未结 1 2181
無奈伤痛
無奈伤痛 2021-02-19 10:25

I have developed a basic custom JTableModel as follows

public class CustomTableModel extends DefaultTableModel {
  List data;
  public CustomTable         


        
1条回答
  •  遇见更好的自我
    2021-02-19 11:11

    ...Even if I have the index, if the table is sorted, my model is not so sophisticated and will return the wrong object...

    You have to use:

    JTable.convertRowIndexToModel( int viewIndex )

    Maps the index of the row in terms of the view to the underlying TableModel. If the contents of the model are not sorted the model and view indices are the same.

    With that index you can access your table model and see what's the object you need.

    Note Table sorting along with this method was introduced in Java 1.6

    0 讨论(0)
提交回复
热议问题