The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Swing & AWT

Thread: Dynamic JProgressBar

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 2 - Last Post: Jul 26, 2007 8:54 AM by: swv
bamboat_3

Posts: 3
Dynamic JProgressBar
Posted: Jul 25, 2007 11:50 PM
  Click to reply to this thread Reply

Dear Experts,

I have created Applet-Servlet Communication Application, where I am trying to save the data via servlet and in return it sending boolean value to the applet.

So, I would like to implement a JProgressBar, which may display at the time of data saving and the value of JProgressBar increase as the boolean value returns from servlet.

Here I need your help, that if any one have an example (either in Applet or Swing Application) of JProgressBar, which may increase bar value upto 10% via Thread notify()method on the boolean value returns in true and after increasing upto 10% get the Thread wait() for the next boolean value returns in true.

I hope you will be understanding the problem, if still have any confusion, or any other ideal to take care of this problem then I am looking forward to you.

Thanking you in advance

Regards,

M.A.Bamboat

chris_e_brown

Posts: 72
Re: Dynamic JProgressBar
Posted: Jul 26, 2007 5:09 AM   in response to: bamboat_3
  Click to reply to this thread Reply

I don't have time to write an example, and in any case, as I haven't seen your code, it's unlikely that I can provide you a code sample that "just works" for your case.

Assuming you're using InputStreams and OutputStreams for sending the data between the client, and that your JProgressBar is visible in the applet, you'll want to set the minimum of the JProgressBar to 0 and the maximum to the number of bytes you need to send. Then, in your data transfer loop, you'll want on each iteration to increment a variable containing the total number of bytes transferred, and set the current total as the current value of the JProgressBar.

I'm assuming that your data transfer loop is running in a background thread, not the event dispatch thread. So you shouldn't call setValue directly on the JProgressBar from this background thread. One simple solution is to call SwingUtilities.invokeLater to pass the value. Ideally, you'll use swingworker, which is designed to efficiently solve this sort of thing without you worrying too much about threading.

- Chris

swv

Posts: 242
Re: Dynamic JProgressBar
Posted: Jul 26, 2007 8:54 AM   in response to: bamboat_3
  Click to reply to this thread Reply

Check out the Swing Tutorial (google it) . That has lots of examples and little running programs of just this sort of thing.




 XML java.net RSS