Results 1 to 3 of 3

Thread: rowIndexes of the table --> rowIndexes of your model

  1. #1
    Join Date
    Nov 2004
    Location
    IL, USA
    Posts
    61

    Default rowIndexes of the table --> rowIndexes of your model

    The tutorial says...

    A SortableTableModel will wrap your own model, handling the sorting. Your own tablemodel will never change when the user sorts a column!
    You will have to take care of the conversion of rowIndexes of the table to the rowIndexes of your model.

    You can use the getSelectedRow(JTable) and getSelectedRows(JTable) of the TableUtils utility class.

    public class TestTableView extends AbstractView {
    private ListTableModel model;
    private JTable table;

    protected JComponent createControl() {
    model = …
    table = TableUtils.createStandardSortableTable(model);

    return new JScrollPane(table);
    }

    private Object getSelectedRow()
    {
    int rowIndex = TableUtils.getSelectedRow(table);
    return model.getRow(rowIndex);
    }
    }

    Any advice how to connect rowIndexes of the table to the rowIndexes of the model after sorting?

    The "TableUtils.getSelectedRow(table)" does not exist.

  2. #2
    Join Date
    Nov 2004
    Location
    IL, USA
    Posts
    61

    Default

    OK, I got it

    selectedRow = lms.getMinSelectionIndex();

    ShuttleSortableTableModel sstm = (ShuttleSortableTableModel) table.getModel();
    selectedRow = sstm.convertSortedIndexToDataIndex(selectedRow);

  3. #3
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    Take a look at the glazedlists project, it handles sorting in tables and lists very well, and you don't have the problem of converting the indexes.

Similar Threads

  1. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  2. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  3. Table framework
    By snpe in forum Swing
    Replies: 2
    Last Post: Aug 17th, 2005, 05:02 PM
  4. Content Provider vs View Model
    By Martin Kersten in forum Swing
    Replies: 21
    Last Post: Mar 10th, 2005, 02:25 PM
  5. Filtered Table model
    By afida in forum Swing
    Replies: 5
    Last Post: Feb 1st, 2005, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •