• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable adding a RowFilter can no longer add to the table get invalid range?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After adding a TableRowSorter to a table and its corresponding model any corresponding adds specifically at firetabletablerowsinserted cause exceptions. It is clear from testing that the GetRowCount() is returning a value past the models range. However it does not make sense to me how to continue to add values to the table after a sorter or filter has been added?

As an example, I set the row filter before adding anything to the table then add a value to the table with the following calls in my model:



The rowcount is of size 1 and the exception is thrown:

java.lang.IndexOutOfBoundsException: Invalid range at javax.swing.DefaultRowSorter.checkAgainstModel(Unknown Source) at javax.swing.DefaultRowSorter.rowsInserted(Unknown Source) at com.gui.model

If I do the same steps without first adding the sorter everything is fine. I assumed that possibly I needed to notify the model that the sorter may have made changes and tried the following but still returns an exception:




So, to summarize I have tried to call the this.fireTableRowsInserted(this.getRowCount(), this.getRowCount()); with both the sorter rowcount and that fails. So, I also tried to check in the update when adding to the table to see if a sorter exists. If the sorter exists I try to update the sorter itself. This does work like the following example. Problem I have with this is two fold.

1. Its calling update on the entire table. Once the table gets large its updating sort for the entire table. When only one row has been added. It really should only need to call sort on the new row. But any time I get specific like sorter.rowsInserted(firstRow, endRow) I get invalid range exceptions.

2. You would think that by updating the model you would niot need to worry about handling another model. I was hoping it would delegate sorting once the model its sorting is updated?




If anyone could try to clarify how best to handle this I would be very grateful. I will post the entire Update method below this method essentialy is the update inside my tablemodel class. All observers of the model add data to the table from this method by using Observer pattern.

 
steve labar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the adding of the data to a Runnable class just to make sure it was not a thread issue. Still get same issue so I know its not that



Then inside the update method that is threaded because its spawned by the Observer I added the following line right before adding data to model. Noty sure if this is necessary but I have heard anything on the SWIng should be done on EDT thread.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic