tags:

views:

23

answers:

1

Hi guys,

I've got a JTable which model is custom that extends AbstractTableModel.

In this the way I get the data is from a list class.

public Object getValueAt(int row, int col)
{
 if ( col == 0 ) {
  return searchThings.getThing(row).getTitle();
 } else if ( col == 1 ) {
  return searchThings.getThing(row).getDate();
 } else {
  return "";
 }
}

This works perfectly, and the dates and titles are all correct. They can all be sorted using the auto method (click the header and it sorts, you can swap around the cols just fine etc) and every thing displays correctly.

The question is this: How do I return the correct item reference or data set? Since they don't keep their original indexes.

Example "test 2" is entry 1. Now if I don't sort the table I can return the row and use that number to look up the position in the list. But if I sort by date, test 2 is now index 4 and I get the wrong data set reference (since I'm looking directly at the original source).

Now there must be a way to find out which was the original data index since the table is showing the correct data! Please assist!

:)

thanks in advance!

A: 

convertRowIndexToModel()!

Simple!

Dorjan
Reformatted link; please revert if incorrect.
trashgod
perfect thanks. ( and the reason I put simples was due to the meerkat advert on at the mo "Simples!" not me mis-spelling :) )
Dorjan