JTable のデータを更新しようとするたびに、このエラーが発生します。
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2
at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:501)
at javax.swing.JTable.convertRowIndexToModel(JTable.java:2620)
at javax.swing.JTable.getValueAt(JTable.java:2695)
at javax.swing.JTable.prepareRenderer(JTable.java:5712)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2069)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1971)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1767)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:751)
at javax.swing.JComponent.paint(JComponent.java:1017)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JComponent.paintChildren(JComponent.java:852)
at javax.swing.JComponent.paint(JComponent.java:1026)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5112)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
at javax.swing.JComponent._paintImmediately(JComponent.java:5060)
at javax.swing.JComponent.paintImmediately(JComponent.java:4870)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
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)
データは正常に更新されているように見えますが、何かがうまくいかず、私のコードを参照していないことが気になります。しばらくデバッグした後、次のコード行が問題の原因であることがわかりました。
public class LoadingLogListThread extends Thread{
...
public void run() {
...
int colNo = rsmd.getColumnCount();
while(rs.next() ){
Object[] objects = new Object[colNo];
for(int i=0;i<colNo;i++){
objects[i]=rs.getObject(i+1);
}
if( objects != null )
aModel.addRow(objects);
count++;
}
mainView.logEntryTable.setModel(aModel);
...
}
ボタンをクリックしてリストをフィルタリングすると、スレッドが作成されて開始されます。その後、データベースに戻って、既にフェッチされたものを超える可能性のあるデータを取得します。後で新しいフェッチが必要かどうかを判断し、その場合にのみ上記を実行し、それ以外の場合は、既にフェッチされた結果をフィルタリングするだけです。