0

I want to trigger a long running background process (coded as a service) from the ui. But I also want to show some progress of that task to the user.

How can I achieve this? (I want to not infringe on decoupling). Is there a best practice to solve it (combining design-patterns, eg. observer and command)?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
matcauthon
  • 2,261
  • 1
  • 24
  • 41
  • The observer pattern on it's own is already a solution to this kind of problem. The Observee just has to inform observers everytime the progress changed. – Mare Infinitus Jun 19 '12 at 08:01

3 Answers3

3

Have look a JProgressBar and changes for progress could be invoked from Runnable#Thread or SwingWorker

mKorbel
  • 109,525
  • 20
  • 134
  • 319
3

Here is another example of a SwingWorker to do the heavy work, and to update a JProgressBar which is contained in the UI to show the progress to the user

Community
  • 1
  • 1
Robin
  • 36,233
  • 5
  • 47
  • 99
1

Here is an example on how to use just the observer pattern to show progress in the UI. With JAVA sample code provided:

Using Observer Pattern to track progress while loading a page

Mare Infinitus
  • 8,024
  • 8
  • 64
  • 113