Announcement Announcement Module
Collapse
No announcement yet.
rowIndexes of the table --> rowIndexes of your model Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    OK, I got it

    selectedRow = lms.getMinSelectionIndex();

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

    Comment


    • #3
      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.

      Comment

      Working...
      X