Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

progress dialog

Thread view: 
cell - 20 Nov 2007 09:25 GMT
Dear all,

I want to open a progress dialog (modal is false) to remind the user
to wait and then open another dialog A. The dialog A needs about 20
seconds to open as it needs to collect data. However, I find that the
progress dialog open but cannot show its content in the dialog.I have
tried to write a class which extends Thread class and repaint the
progress dialog about 0.5sec inside it. However, it still cannot
repaint during opening dialog A.

Could anyone tell me some hints to solve it?

Thanks!
RedGrittyBrick - 20 Nov 2007 10:27 GMT
> Dear all,
>
[quoted text clipped - 5 lines]
> progress dialog about 0.5sec inside it. However, it still cannot
> repaint during opening dialog A.

When you say "repaint" it sounds to me that you are messing around at
too low a level. It sounds like your problem is you are blocking the
EDT. You just need to arrange threads appropriately and all will work fine.

> Could anyone tell me some hints to solve it?

Your description is a bit confusing to me but if I understand it
correctly, the approach I have used is for dialog A to extend Observable
(or to receive an Observable during construction). The progress dialog
implements Observer and it's update() method is used to update a
progress bar or some other indicator.

I'd have Dialog A display itself empty and start a new (i.e. non EDT)
thread to go and retrieve it's data. As this thread progresses it would
call notifyObservers() (or update the passed Observable). Along the way
(or at the end) it would update A's contents (using
SwingUtilities.invokeLater() to ensure GUI work happens on the EDT).

I'm simplifying somewhat since I'd separate model from view.

If you update the GUI too frequently it will slow things down so I find
it best to throttle GUI updates of this sort to once every 250 ms (for
example). When adding rows to a JTable, I don't call
fireTableRowsInserted() for every row, I check elapsed time since last
update.

Because notifyObservers in A is called from a thread other than the EDT,
the update() method should take care to use Swingutilities.invokeLater()
to perform any Swing methods such as updating a JProgressBar.

Using threads is tricky. I am not an expert, I am hoping the real
experts will correct any blunders in the above.

If you put together a small SSCCE this could be clarified more easily.
http://mindprod.com/jgloss/sscce.html
http://homepage1.nifty.com/algafield/sscce.html

P.S.  As of Java 1.3, SwingUtilities.invokeLater is just a cover for
java.awt.EventQueue.invokeLater(). You should probably use the latter.
Andrew Thompson - 20 Nov 2007 10:28 GMT
...
>Could anyone tell me some hints to solve it?

Prepare an SSCCE*.  If the solution does not become obvious
while preparing it, post the SSCCE here for further investigation.

Note that in order to take 'a lot of time' to prepare the second
dialog, it might be necessary to throw in some arbitrary 'work'
for the simpler version (e.g. calculate the average value of a million
random numbers).

* <http://www.physci.org/codes/sscce.html>

Signature

Andrew Thompson
http://www.physci.org/

Daniel Pitts - 20 Nov 2007 17:21 GMT
> Dear all,
>
[quoted text clipped - 9 lines]
>
> Thanks!

From your description, it sounds like your "collect data" process is
happening on the Event Dispatch Thread.  You would be better off passing
that work into a new thread (see SwingWorker), and when that work is
finished, firing off an event that opens your new dialog.

I suggest reading more about Swing and Threads.  Google for that term.
I also suggest reading the book Java Concurrency in Practice.  It
explains a lot of the subtleties of working in Java when dealing with
multiple threads.  Most modern Java apps are multithreaded, whether the
authors know it or not.

More info on Java Concurrency in Practice:
<http://virtualinfinity.net/wordpress/technical-book-recommendations/java-concurr
ency-in-practice/
>

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.