Search code examples
javaswingjtablecellfill

update and watch jtables cells values while filling inside a loop


in my java application I'm using some jtables and I fill each cell using jtable.setvalueat(i,j) inside a loop.

When jtable1 is filled, the loop for filling Jtable2 starts inmidiatelly and so on.

Everything works pretty good, but my application seems to be freezed with all cells in blank until all jtables and loops are finished and finally all jtables appear full filled at once.

If I use a JOptionPane to show some message after each loop ending I will see those cells have been filled up to that step.

My question: Is there any way or trick to show cells values while are filled and not to wait until loop ends????

thanks a lot for your advises.


Solution

  • The loops that fill one TableModel after another block the event dispatch thread; the intervening JOptionPane allows the EDT to process the waiting updates. SwingWorker is a common way to publish() interim results; examples are seen in the API and Concurrency in Swing.