Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] JProgress Bar

Started by Joker_Of_Hearts Jan 10, 2008 at 12:04 AM 4 replies 1k views
Original Post
Joker_Of_Hearts
Joker_Of_Hearts
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
Joker_Of_Hearts
Joker_Of_Hearts
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
Antheus
Antheus
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?
Joker_Of_Hearts
Joker_Of_Hearts
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]
CaptainJester
CaptainJester
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 URLConnectionset up a byte array of size 8192(byte buffer[] = new byte[8192])create a ByteArrayOutputStreamin 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 -1create a ByteArrayInputStream and pass ByteArrayOutputStream.toByteArray() to the constructorpass 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]
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.