java - Selected Row in JTable along with Sorting -


i have odd issue jtable.

i put data in jtable db. when user double clicks on cell, copies cell contents of first column of row user double clicked. far, works perfect.

the problem arises when user sorts jtable clicking on header. when table has been sorted , when user double clicks on row, doesn't stored on row's first column. copies stored on first column of row when jtable not sorted.

any ideas?

problem:

the problem here getting initial rows indexes in jtable tablemodel, , not relevants row indexes shown in table view.

solution:

you can map shown indexes of sorted jtable relevants ones in datamodel using convertrowindextomodel(index) method takes in input row index in view , returns index of corresponding row in model.

let's have following jtable:

tablemodel mymodel = createmytablemodel(); jtable table = new jtable(mymodel); table.setrowsorter(new tablerowsorter(mymodel)); 

and loop throught model indexes , use method each index corresponding 1 in tablemodel:

table.getrowsorter().convertrowindextomodel(0); // index 0 here 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -