java.lang.IndexOutOfBoundsException: Invalid range

Coderanch | Paul Hayabusa | 4 years ago
  1. 0

    How to color JTable cell without a renderer?

    Coderanch | 4 years ago | Paul Hayabusa
    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

    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(Unknown Source)
      2. javax.swing.DefaultRowSorter.rowsUpdated(Unknown Source)
      3. javax.swing.JTable.notifySorter(Unknown Source)
      4. javax.swing.JTable.sortedTableChanged(Unknown Source)
      5. javax.swing.JTable.tableChanged(Unknown Source)
      6. javax.swing.table.AbstractTableModel.fireTableChanged(Unknown Source)
      7. javax.swing.table.AbstractTableModel.fireTableRowsUpdated(Unknown Source)
      7 frames
    3. Unknown
      1. JTableDemo$MyColorModel.setColorAt(
      2. JTableDemo$AnalyzeButton$1.actionPerformed(
      2 frames
    4. Java RT
      1. javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      2. javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      3. javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      4. javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      5. javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      6. java.awt.Component.processMouseEvent(Unknown Source)
      7. javax.swing.JComponent.processMouseEvent(Unknown Source)
      8. java.awt.Component.processEvent(Unknown Source)
      9. java.awt.Container.processEvent(Unknown Source)
      10. java.awt.Component.dispatchEventImpl(Unknown Source)
      11. java.awt.Container.dispatchEventImpl(Unknown Source)
      12. java.awt.Component.dispatchEvent(Unknown Source)
      13. java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      14. java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      15. java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      16. java.awt.Container.dispatchEventImpl(Unknown Source)
      17. java.awt.Window.dispatchEventImpl(Unknown Source)
      18. java.awt.Component.dispatchEvent(Unknown Source)
      19. java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      20. java.awt.EventQueue.access$200(Unknown Source)
      21. java.awt.EventQueue$ Source)
      22. java.awt.EventQueue$ Source)
      23. Method)
      24.$1.doIntersectionPrivilege(Unknown Source)
      25.$1.doIntersectionPrivilege(Unknown Source)
      26. java.awt.EventQueue$ Source)
      27. java.awt.EventQueue$ Source)
      28. Method)
      29.$1.doIntersectionPrivilege(Unknown Source)
      30. java.awt.EventQueue.dispatchEvent(Unknown Source)
      31. java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      32. java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      33. java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      34. java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      35. java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      36. Source)
      36 frames