gpt4 book ai didi

java - 为什么我需要在 fireTableRowsInserted() 之前调用 getRowSorter().modelStructureChanged()

转载 作者:行者123 更新时间:2023-11-30 04:48:03 25 4
gpt4 key购买 nike

我有一个扩展 AbstractTableModel 的表。当数据到达时,我删除行并用新数据重新创建它们。我不明白的是为什么我必须调用以下内容:

getRowSorter().modelStructureChanged();

打电话之前

fireTableRowsInserted();

如果我不这样做,fireTableRowsInserted() 会抛出以下异常:

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 1
at javax.swing.DefaultRowSorter.setModelToViewFromViewToModel(DefaultRowSorter.java:717)
at javax.swing.DefaultRowSorter.rowsInserted0(DefaultRowSorter.java:1046)
at javax.swing.DefaultRowSorter.rowsInserted(DefaultRowSorter.java:851)
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 javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
at javax.swing.table.AbstractTableModel.fireTableRowsInserted(AbstractTableModel.java:215)
at ems.ui.components.BoundTable$BoundTableModel.addRow(BoundTable.java:189)
at ems.ui.components.BoundTable.loadData(BoundTable.java:315)
at ems.ui.components.BoundTable.modelChanged(BoundTable.java:333)
at ems.model.BaseDataModel.notifyPropertyChange(BaseDataModel.java:541)
at ems.model.BaseDataModel.listLoadedFully(BaseDataModel.java:456)
at
at ems.network.HTTPProtobufPoller$2.run(HTTPProtobufPoller.java:107)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

最佳答案

如果您重新创建整个表(删除行然后重新插入它们),您至少需要调用“fireTableDataChanged”(如果您很懒并且不想告诉模型到底发生了什么变化而只是希望它重新计算所有内容:- )。

“fireTableRowsInserted”只能在将数据追加到表模型时使用(即,不要从表模型中删除数据)。

关于java - 为什么我需要在 fireTableRowsInserted() 之前调用 getRowSorter().modelStructureChanged(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10501969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com