When you are executing something like
FillTable fff = new FillTable(model1);
fff.execute();
model1 = fff.model;
jTable3.setModel(model1);
then the line model1 = fff.model
will most likely be executed before the SwingWorker has finished. The execute
call will cause the work to be done in the background, and the next lines well be executed regardless of whether the work already finished or not.
A general approach could be to use the model in your done()
method, roughly like this:
protected void done() {
try {
TableModel model = get();
jTable3.setModel(model); // Use it here!
} catch (InterruptedException | ExecutionException ex) {
ex.printStackTrace();
}
}
(You'll have to pass a reference of jTable3
to your SwingWorker for this - that is, pass it to the constructor and store it as a field in the SwingWorker).
There may be more elegant solutions, but based on the code that was provided so far, this at least seems to be the reason for the error and a possible solution.