Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Images

Status
Not open for further replies.

owls

Instructor
Oct 10, 2002
23
0
0
US
Can someone please tell me how to get an image into a panel. I am using JBuilder to create my GUI. There doesn't seem to be a bean that is used exclusively for images. If you can tell me how to do it through Jbuilder, that would be great. If not I would even greatly appreciate the code that would do it. I tried using the setIcon method for a label but it wasn't working. I'm not sure how it wants me to list my file directory within the method.

Please help. I am a first time teacher of Java and would love to use graphics to enhance my students interest in programming.
 
This code should work using ImageIcon and a MediaTracker. BTW, I have had mixed results with IIS as the web server. Apache seems to never fail, but IIS doesn't do well when it gets busy.

private ImageIcon getIcon(String f) {
MediaTracker tr = new MediaTracker(this);
Image im;
ImageIcon ii = null;
int retries = 3;
try {
im = getImage(f);
tr.addImage(im, 0);
ii = new ImageIcon(im);
} catch( Exception e) {
System.out.println("Bad Filename: "+f);
System.out.println("Error: "+e);
}
try {
tr.waitForAll();
} catch (InterruptedException e) {
System.out.println("Interrupted while loading Image");
}
return ii;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top