Search code examples
javauser-interfacejtabletablemodeldefaulttablemodel

Equivalent of getSelected column method of JTable in DefaultTableModel


I was re designing my codes with formerly using

JTable jtable = new JTable();
int selectedIndex = jtable.getSelectedColumn();
//implementations

Now, I need to use DefaultTableModel. Is there a method or implementation that is related to this method of JTable? Thanks!


Solution

  • A TableModel has nothing to do with the selected column of the JTable.

    It doesn't matter what TableModel you use with the JTable, you still use

    int selectedIndex = table.getSelectedColumn();
    

    method to get the selected column.

    Of course, there is no selected column when you first create the JTable. The user must select the column or you must set the selection on a particular cell of the table.

    So you only use the getSelectedColumn() method in response to some kind of user event.