🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10167

Re: Swing, Threads, and Progress meters.

#10167
From: Olaf Raether
Date: Thu, 04 Nov 1999 00:00
50 lines
2808 bytes
John,

take a look at the ProgressMonitor class in javax.swing

Olaf

On Wed, 3 Nov 1999 03:28:44 -0500, John P. McGrath <mcgrath@enter.net>
wrote:

>I have a Swing desktop application that is currently written without any 
>explicit thread creation.  Most of the operations that the program 
>performs are quite simple and take little time.  However, there is an 
>operation that can be rather lengthy -- on the order of 5 seconds, but 
>with complex data it might run up to 20 or 30 seconds.
>
>Currently, the GUI is pretty much dead while this operation is ongoing.  
>The fact that it does not respond to user input is a concern, but it is 
>not critical since there is little that the user would be allowed to do 
>while this is running.  However, it would be useful to give the user the 
>option of canceling.
>
>But my primary concern is that the GUI does not _look_ like it is doing 
>anything.  To solve this problem, I would like to show a ProgressMeter 
>while the operation is performed, but I am not sure of the best way to do 
>this.  I am hoping that the solution will also provide the capability of 
>canceling the operation.
>
>The ProgressMeter / ProgressMonitor examples I have seen all perform the 
>long task in a separate thread, and my application currently does all of 
>its work in the event-dispatch thread.  I am concerned that moving this 
>work to a separate thread may cause problems.
>
>The application uses a Model-View architecture.  The Swing view 
>components are registered as listeners on the model objects, which use 
>javax.swing.event.EventListenerList for registering listeners and firing 
>events.  All GUI updates are triggered through changes to the model.
>
>The long operation perform extensive modifications of the model, which 
>results in many events fired at the Swing view components, which causes 
>these components to change their appearance, create some new components 
>and remove others, etc.  This works fine, since it is all happening from 
>the event-dispatch thread.  But if I were to create a separate thread to 
>perform the operation, this would violate the Swing single-thread rule.
>
>Does anyone have any comments or suggestions as how to deal with this?
>
>-- 
>John P. McGrath
><mcgrath@enter.net>
><jpm@nscs.fast.net>
Technical Details
Message-ID: <38212c72.1261133@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.1289bc46f1d0f7aa989685@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,eebaae9990e98781
X-Google-Attributes: gid111d45,public
From: o.raether@windsoft.de (Olaf Raether)
Subject: Re: Swing, Threads, and Progress meters.
Date: 1999/11/04
Message-ID: <38212c72.1261133@forums.inprise.com>
X-Deja-AN: 544280221
References: <MPG.1289bc46f1d0f7aa989685@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing