Skip to main content

JXTable convertRowIndexToModel wrong result after sort?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
malolasi
Offline
Joined: 2011-08-10

I have a JXTable in which a model is a List of distinct objects. There is a problem when I try to map the view index to model index after sorting the view by the selected column header. Using this code,

[prettify]<span class="kwd">int</span><span class="pun">[]</span><span class="pln"> selecteds </span><span class="pun">=</span><span class="pln"> getTableMember</span><span class="pun">().</span><span class="pln">getSelectedRows</span><span class="pun">();</span><span class="pln"><br /></span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">selecteds </span><span class="pun">!=</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> selecteds</span><span class="pun">.</span><span class="pln">length </span><span class="pun">></span><span class="pln"> </span><span class="lit">0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br />    </span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> row </span><span class="pun">:</span><span class="pln"> selecteds</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br />        </span><span class="kwd">int</span><span class="pln"> rr </span><span class="pun">=</span><span class="pln"> getTableMember</span><span class="pun">().</span><span class="pln">convertRowIndexToModel</span><span class="pun">(</span><span class="pln">row</span><span class="pun">);</span><span class="pln"><br />            </span><span class="typ">System</span><span class="pun">.</span><span class="pln">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">row</span><span class="pun">+</span><span class="str">":"</span><span class="pun">+</span><span class="pln">rr</span><span class="pun">);</span><span class="pln"><br />    </span><span class="pun">}</span><span class="pln"><br /></span><span class="pun">}</span><span class="pln"><br /></span>[/prettify]

the TableModel contain a List of Object that class generated by Thrift and I'm sure there's an Id field to distinct them.

I get this result:

11:240
12:328
13:1174
14:328
15:1174

I cannot understand why different view indexes map to the same model index?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
malolasi
Offline
Joined: 2011-08-10
kleopatra
Offline
Joined: 2003-06-11

Glad you solved your problem - and glad that it wasn't a bug in JXTable :-)

Cheers, Jeanette