Ignore:
Timestamp:
2022-11-22T14:37:25+01:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #20849: WARNING: row index is bigger than sorter's row count. Most likely this is a wrong sorter usage

This is caused by the ordering of the TableModelListeners for
availableSourcesModel. While not documented, Java fires the listeners in reverse
order, so we want to remove the listener that updates the sorter and add the
column width adjustment listener, and then re-add the listener that updates the
sorter.

The alternative to adding/removing the listener for the sorter is to use an
AtomicReference for tblAvailableSources and add the adjustColumnWidth listener
before creating the tblAvailableSources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r18208 r18603  
    152152        this.availableSourcesModel = new AvailableSourcesModel();
    153153        this.tblAvailableSources = new ScrollHackTable(availableSourcesModel);
     154        // This add/remove listener code is needed to fix #20849. Java fires table listeners in the reverse order
     155        // in which they were added, and we need the model to have been updated before we call the adjustColumnWidth code.
     156        // So we remove the JTable and re-add it as a listener after we add the column width adjustment
     157        availableSourcesModel.addTableModelListener(e -> TableHelper.adjustColumnWidth(tblAvailableSources, 0, 800));
     158        availableSourcesModel.removeTableModelListener(this.tblAvailableSources);
     159        availableSourcesModel.addTableModelListener(this.tblAvailableSources);
    154160        this.tblAvailableSources.setAutoCreateRowSorter(true);
    155161        this.tblAvailableSources.setSelectionModel(selectionModel);
     
    191197        // Force Swing to show horizontal scrollbars for the JTable
    192198        // Yes, this is a little ugly, but should work
    193         availableSourcesModel.addTableModelListener(e -> TableHelper.adjustColumnWidth(tblAvailableSources, 0, 800));
    194199        activeSourcesModel.addTableModelListener(e -> TableHelper.adjustColumnWidth(tblActiveSources, canEnable ? 1 : 0, 800));
    195200        activeSourcesModel.setActiveSources(getInitialSourcesList());
Note: See TracChangeset for help on using the changeset viewer.