Jump to content
  • Advertisement
Sign in to follow this  
Joker_Of_Hearts

[java] JProgress Bar

This topic is 3905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there! I need some help with JProgress bars... I have googled some stuff, and I either don't understand the ways, or they aren't what I need. All the tutorials just load a bar from nothing, just to make it load, but I need a bar which can give progress from loading an image. Ok. so let me begin. Pardon my speech abilities. So I am writing a program for my own use, and others who went with me on a trip. I have uploaded images to my website from a trip we took. Now, I am writing a program (a Picture Viewer) in java to view the images in an easy way. What I have accomplished is loading an image from the internet when you click a button. (Basic, I know, but thats where it all starts, from the ground up.) Now what I want is when the button is click, and the image is being loaded, I need a progress bar to give status on where the image is at during the loading process. Like what percentage has loaded. I know someone can help me out there in a forum full of programs. It would be much appreciated if someone could explain this to me, give me a link to a good tutorial, etc. Thanks, -Geo

Share this post


Link to post
Share on other sites
Advertisement
Sorry lol, I neglected to mention that I have the JProgressbar set up and all that jazz in my program, but what I was looking for was some help on how to make the JProgressbar show the loading status as the program loads and image from the URL. If its there, I have looked and have not understood which part of the tutorial could help me.

Sorry,
-Geo

Share this post


Link to post
Share on other sites
That would depend on how you're loading the image.

Does it provide a progress listener, or does it block until it's fully loaded?

Share this post


Link to post
Share on other sites
How can you change the way the image is being loaded?

Through firefox, the image is slowly loaded, in horizontal rows till its done, but through my program, all it does is wait till its all loaded, then fully loads the image in one fell swoop.


Edit: er.... Anyone?

[Edited by - Joker_Of_Hearts on January 13, 2008 1:13:10 AM]

Share this post


Link to post
Share on other sites
You would have to manage the image loading yourself. Are you using ImageIO to load your image? Here is some psuedocode to load it yourself.


Create URL to image.
call getConnection() on URL(returns a URLConnection)
call getContentLength() on the URLConnection(this gives you the max size for the JProgressBar)
call getInputStream() from the URLConnection
set up a byte array of size 8192(byte buffer[] = new byte[8192])
create a ByteArrayOutputStream
in a loop
- read from InputStream into buffer[]
- use size returned from read() to write to ByteArrayOutputStream
- use size to update JProgressBar
- end loop if size from read() is -1

create a ByteArrayInputStream and pass ByteArrayOutputStream.toByteArray() to the constructor
pass the ByteArrayInputStream to ImageIO.read() to create the image.




If the call to getContentLength() returns 0 then you are out of luck.

[Edited by - CaptainJester on January 14, 2008 6:17:54 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!