Reputation: 11
I have a GUI and on click event, I am calling database queries to generate multiple charts. I cannot see any chart until all the charts are get completed means there is some problem with GUI components which moves to the next chart before the first chart get complered and show it's contents. What could be the possible reason and how to avoid such problem ?
Upvotes: 0
Views: 692
Reputation: 692073
There is no problem with the components. There is a problem with your design. You're doing the long-running queries and the updates of the charts in a single method run in the event dispatch thread. By doing so, the EDT is completely blocked and can't repaint anything until all the queries have been run and all the charts have been generated.
Use a background thread to execute the queries, and generate a chart, in the EDT, each time one query is finished. The SwingWorker class helps doing that. Read its API doc, and the tutorial about concurrency in Swing.
Upvotes: 3