سؤال

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.

هل كانت مفيدة؟

المحلول

  1. Show the busy dialog.

  2. Start SwingWorker and do all long-running tasks in the background (database)

  3. When done, create big dialog with data from database (inside SwingWorker.done( method))

  4. Hide busy dialog, show big dialog.

نصائح أخرى

You should better use SwingWorker:

  1. create the dialog with busy label, create the swing worker
  2. start the swingworker (it will asynchronously load data from DB, prepare control for the main dialog)
  3. in SwingWorker's done() method, hide your first small dialog and show the main one
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top