JAVA - strange problem (possibly a thread issue) with JTable & Model

I use 2 tables (JTable) with their DefaultTableModels templates. The first table is already populated. A second table is populated for each row of the first table (using SQL Query). My goal is to export each row of the first table with the corresponding rows of the second in the Excel file.

I do this with for (for each row of the 1st table), in which I write the row of the 1st table in the Excel file, then fill the second table (for this row of the 1st table), I get each row from the table ( from it really really) and put it in an excel file in the current row of the 1st table. This means that if I have n rows in the first table, I will clear and repeat the second table n times.

All this code is called in a separate thread.

PROBLEM: Everything works fine, especially that I get some exceptions. The strange thing is that I do not get anything false in my result. Excel file is perfect.

Some of the exception lines are:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0> = 0 in java.util.Vector.elementAt (Vector.java:427) in javax.swing.table.DefaultTableModel.getValueAt (DefaultTableModel.java: 632) in javax.swing.JComponent.paint (JComponent.java:1017) in javax.swing.RepaintManager.paint (RepaintManager.java:1220) in javax.swing.RepaintManager.paintDirtyRegions (RepaintManager.java:803)

, , , - . RepaintManager paintDirtyRegions . , , , , . F5 2- , . - . , , , , .

, :

  • , ? , , Java Java GUI .

  • GUI ( ), , SQL Query ? . , , . . , , , , , , java. .

+3
2

API Swing , : , . , , .

/ SwingUtilities.invokeLater() SwingUtilities.invokeAndWait().

JTable, TableModel, javax.swing summary summary javadocs. -, , , Thread Dispatch Thread.

, , , , . .. ( Swing) , Swing , .

+2

, null getValueAt (int row, int column). , , - , . swing api , , .

swing.

http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html

+1

Source: https://habr.com/ru/post/1750276/


All Articles