Reputation: 4547
I have a JButton that when i click on it, i load some data from a database + initialize a JDialog that has many controls + fill those controls with the loaded data then show that slow JDialog. This takes about 3 to 5 seconds to finally show the JDialog, which causes the program to freeze in a bad manner.
I have created a small JDialog with a JXBusyLabel from SwingX to show a busy label while loading and initializing such slow processes. But how can i run this busy label JDialog in the EDT while initializing the slow dialog ?
Note: Loading the data from the db is not slow, but initializing the heavy JDialog and its components causes that slow processing.
Upvotes: 1
Views: 647
Reputation: 2070
You should better use SwingWorker:
Upvotes: 0
Reputation: 80340
Show the busy dialog.
Start SwingWorker and do all long-running tasks in the background (database)
When done, create big dialog with data from database (inside SwingWorker.done( method))
Hide busy dialog, show big dialog.
Upvotes: 5