• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why DefaultRowSorter throws Exception?  RSS feed

 
Larry Krigbaum
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been fussing with Tables and Table Models for some time and several of you have helped along the way. I've decided my understanding of table models is so sketchy I need to throw out most of what I've done and start over and move more slowly until I get a better handle on this stuff. A brief intro: I'm going to be doing a lot with tables which will need to be fully editable with various renderers and editors. It seems like I'm going to eventually need to use the AbstractTableModel so I'm starting off using it although it's not actually necessary yet.

I have a couple of early questions. The first is that using the DefaultRowSorter is causing an IndexOutOfBounds exception with an invalid range when I try to add a row. If I comment out the offending line 38, adding a row seems to work okay. What does the DefaultRowSorter look at that's causing my problem?

Also, when I call addRow, I want the new row to be empty. I can't get it to add the row, however, unless I've initialized the new row so that row.sortOrder has a value. Why is that and how do I correct it.

Any suggestions on these problems would be appreciated. Also, if you have any suggestions on how I can improve or clean up the code looking to the future, I would love to hear it, and I'd especially like to hear any ideas for good tutorials for using table models. I've been using the Core Java books, Just Java, and the Oracle tutorial on tables.

Thanks!


Debugging output:

getRoleCard():
getColumnCount():
Returned 2
getColumnCount():
Returned 2
getColumnCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
arg is :Role Data:
Clicked on Role
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getRowCount():
Returned 2
getValueAt():
getValueAt(0, 0):
Returned ECC
getRowCount():
Returned 2
getValueAt():
getValueAt(0, 1):
Returned 0
getRowCount():
Returned 2
getRowCount():
Returned 2
getValueAt():
getValueAt(1, 0):
Returned Portal
getRowCount():
Returned 2
getValueAt():
getValueAt(1, 1):
Returned 3
Add was pressed
row.xrole = null
row.sortOrder = 0
size = 3
getRowCount():
Returned 3


Exception:

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Invalid range
at javax.swing.DefaultRowSorter.checkAgainstModel(DefaultRowSorter.java:921)
at javax.swing.DefaultRowSorter.rowsInserted(DefaultRowSorter.java:861)
at javax.swing.JTable.notifySorter(JTable.java:4269)
at javax.swing.JTable.sortedTableChanged(JTable.java:4117)
at javax.swing.JTable.tableChanged(JTable.java:4394)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:296)
at javax.swing.table.AbstractTableModel.fireTableRowsInserted(AbstractTableModel.java:231)
at SMC.RoleTableModel.addRow(RoleCard.java:143)
at SMC.RoleCard$1.actionPerformed(RoleCard.java:61)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)


Code:
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Larry Krigbaum wrote:I've been fussing...

Larry,

Please DontWriteLongLines. It makes your thread very hard to read. I've broken yours up this time, but for future reference, please remember:
80 characters max.
And that includes string literals AND comments.

Thanks.

Winston
 
Larry Krigbaum
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Winston. I'll watch that in the future. I didn't realize I had lines that long.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!