i have a problem during adding rows to my tablemodel for my jxtable.

The following exception will be thrown:

Exception in thread "Thread-9" java.lang.IndexOutOfBoundsException: Invalid range
at javax.swing.DefaultRowSorter.checkAgainstModel(DefaultRowSorter.java:904)
at javax.swing.DefaultRowSorter.rowsInserted(DefaultRowSorter.java:844)
at javax.swing.JTable.notifySorter(JTable.java:4258)
at javax.swing.JTable.sortedTableChanged(JTable.java:4106)
at javax.swing.JTable.tableChanged(JTable.java:4383)
at org.jdesktop.swingx.JXTable.tableChanged(JXTable.java:1524)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
at javax.swing.table.AbstractTableModel.fireTableRowsInserted(AbstractTableModel.java:215)
at javax.swing.table.DefaultTableModel.insertRow(DefaultTableModel.java:359)
at javax.swing.table.DefaultTableModel.addRow(DefaultTableModel.java:333)
at javax.swing.table.DefaultTableModel.addRow(DefaultTableModel.java:344)
at de.mudisar.MainWindow.addRow(MainWindow.java:2358)
at de.mudisar.dataloader.SelectionDataLoader.run(SelectionDataLoader.java:46)

I call the method which fills the model from a thread because that could be more then 10000 entries and otherwise my program will be freezed.

I am sorry that i can't paste the code but this is very critical in my company.

The exception comes at that line if i do:

infomodel.addRow(new Object[{1,2,3,4,5,6,7,8});

Have anybody an idea why this exception occurs?

With best

有帮助吗?

解决方案

Exception in thread "Thread-9" java.lang.IndexOutOfBoundsException: Invalid range
at javax.swing.DefaultRowSorter.checkAgainstModel(DefaultRowSorter.java:904)
at javax.swing.DefaultRowSorter.rowsInserted(DefaultRowSorter.java:844)
at javax.swing.JTable.notifySorter(JTable.java:4258)

Thread-9 does not sound like the EDT. You shouldn't modify the model which is already placed on a table on another thread then the EDT. See the Concurrency in Swing tutorial for more information.

You could use e.g. SwingUtilities.invokeLater to schedule the update of the EDT. Or in case you have to re-populate your whole model, it might be easier to create a new TableModel on the worker thread, and replace the model in one go on the EDT

其他提示

Maybe you add too many columns to a row - more than there are in model.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top