java.lang.IndexOutOfBoundsException: Invalid range

Coderanch | Larry Krigbaum | 3 years ago
  1. 0

    Why DefaultRowSorter throws Exception?

    Coderanch | 3 years ago | Larry Krigbaum
    java.lang.IndexOutOfBoundsException: Invalid range
  2. 0

    GlazedLists clear throws error on sorted JTable

    Stack Overflow | 3 years ago | langm
    java.lang.IndexOutOfBoundsException: Invalid range
  3. 0

    JXTable Invalid range Problem | 1 year ago
    java.lang.IndexOutOfBoundsException: Invalid range
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    To reproduce: # Create a {{JXTreeTable}} with the root hidden and 3 child nodes # Remove the first and last child by removing them from the model and then calling {{TreeModelSupport.fireChildRemoved}} for each individually in display order. After the second {{rowsDeleted}} event is handled by the display table's row sorter, you will get the following exception: {noformat} Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Invalid range at javax.swing.DefaultRowSorter.rowsDeleted( at org.jdesktop.swingx.sort.DefaultSortController.rowsDeleted( at javax.swing.JTable.notifySorter( at javax.swing.JTable.sortedTableChanged( at javax.swing.JTable.tableChanged( at org.jdesktop.swingx.JXTable.tableChanged( at javax.swing.table.AbstractTableModel.fireTableChanged( at javax.swing.table.AbstractTableModel.fireTableRowsDeleted( at org.jdesktop.swingx.JXTreeTable$TreeTableModelAdapter$ at java.awt.event.InvocationEvent.dispatch( at java.awt.EventQueue.dispatchEventImpl( at java.awt.EventQueue.access$000( at java.awt.EventQueue$ at java.awt.EventQueue$ at Method) at$1.doIntersectionPrivilege( at java.awt.EventQueue.dispatchEvent( at java.awt.EventDispatchThread.pumpOneEventForFilters( at java.awt.EventDispatchThread.pumpEventsForFilter( at java.awt.EventDispatchThread.pumpEventsForHierarchy( at java.awt.EventDispatchThread.pumpEvents( at java.awt.EventDispatchThread.pumpEvents( at {noformat} This happens because the first child removed event is processed after both children are removed from the tree within {{JXTreeTable.TreeTableModelAdapter}} since the {{fireTableRowsDeleted}} is called within a {{SwingUtilities.invokeLater}}. On the first call, the {{modelRowCount}} is updated which will then be 1. On the second call, the {{firstRow}} and {{endRow}} parameters will be 1 and the {{IndexOutOfBoundsException}} will be thrown. The only workaround I've found for this is the following: {code} // Add new child modelSupport.fireChildAdded(...); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Remove target children and call fireChildRemoved for each individually SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Remove new child modelSupport.fireChildRemoved(...); } }); } }); {code} If the new child you add and remove has no display text, this isn't noticeable to the user unless the row it takes up causes the table to display a scroll bar which then flashes momentarily. Ideally, the handling would be synchronous, although the comment in {{JXTreeTable.TreeTableModelAdapter.getTreeModelListener}} indicates that this caused problems. The next best solution would be to change the logic in {{delayedFireTableDataChanged}} to only call {{fireTableRowsDeleted}} if the {{min}} index is less than the total rows and snap {{max}} to the total rows if it is more. I haven't tested either of these, so I'm not sure if they will work, but it seems like they could. JIRA | 4 years ago | rkeen
    java.lang.IndexOutOfBoundsException: Invalid range
  6. 0

    The follow functions initiate the sorter just after initializing the compon

    Oracle Community | 4 years ago |
    java.lang.IndexOutOfBoundsException: Invalid range

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IndexOutOfBoundsException

      Invalid range

      at javax.swing.DefaultRowSorter.checkAgainstModel()
    2. Java RT
      1. javax.swing.DefaultRowSorter.checkAgainstModel(
      2. javax.swing.DefaultRowSorter.rowsInserted(
      3. javax.swing.JTable.notifySorter(
      4. javax.swing.JTable.sortedTableChanged(
      5. javax.swing.JTable.tableChanged(
      6. javax.swing.table.AbstractTableModel.fireTableChanged(
      7. javax.swing.table.AbstractTableModel.fireTableRowsInserted(
      7 frames
    3. SMC
      1. SMC.RoleTableModel.addRow(
      2. SMC.RoleCard$1.actionPerformed(
      2 frames
    4. Java RT
      1. javax.swing.AbstractButton.fireActionPerformed(
      2. javax.swing.AbstractButton$Handler.actionPerformed(
      3. javax.swing.DefaultButtonModel.fireActionPerformed(
      4. javax.swing.DefaultButtonModel.setPressed(
      5. javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
      6. java.awt.Component.processMouseEvent(
      7. javax.swing.JComponent.processMouseEvent(
      8. java.awt.Component.processEvent(
      9. java.awt.Container.processEvent(
      10. java.awt.Component.dispatchEventImpl(
      11. java.awt.Container.dispatchEventImpl(
      12. java.awt.Component.dispatchEvent(
      13. java.awt.LightweightDispatcher.retargetMouseEvent(
      14. java.awt.LightweightDispatcher.processMouseEvent(
      15. java.awt.LightweightDispatcher.dispatchEvent(
      16. java.awt.Container.dispatchEventImpl(
      17. java.awt.Window.dispatchEventImpl(
      18. java.awt.Component.dispatchEvent(
      19. java.awt.EventQueue.dispatchEventImpl(
      20. java.awt.EventQueue.access$200(
      21. java.awt.EventQueue$
      22. java.awt.EventQueue$
      23. Method)
      26. java.awt.EventQueue$
      27. java.awt.EventQueue$
      28. Method)
      30. java.awt.EventQueue.dispatchEvent(
      31. java.awt.EventDispatchThread.pumpOneEventForFilters(
      32. java.awt.EventDispatchThread.pumpEventsForFilter(
      33. java.awt.EventDispatchThread.pumpEventsForHierarchy(
      34. java.awt.EventDispatchThread.pumpEvents(
      35. java.awt.EventDispatchThread.pumpEvents(
      36 frames