This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
It's advisable to put your images in an images folder, store your images folder in your classpath and use Class.getResource() to locate your images. For example
I don't think the problem is the code. I copied and pasted it to the desktop along with the picture and it worked. Something is up with NetBeans I think. It might also be because I am using subversion. Would any of these cause a problem that you know of? And if so how do I fix it. (I tried that way first and it didn't work either.)
I hope this helps. This tutorial shows how to add your images to the classpath. I don't think that subversion is the problem because the images should be loaded from the classpath and not SVN.
If you want to stick to your old code, use ImageIcon pc = new ImageIcon("src/file.gif");
or move file.gif from the src folder to the project folder and use ImageIcon pc = new ImageIcon("file.gif");
The problem with this is that your code is reliant on the working directory or an absolute path instead of the classpath. Also, the getResource() method allows you to verify that the image is available so that you can take appropriate action if it isn't.
I don't have a problem with changing my code, but nothing seems to work. I have tried several different types of code, using relative paths and specific paths, but it doesn't display the picture. If I got anything to work I would defently try a specific path, but I don't know what the problem is. I also tried to change the icon, but that didn't work either. Do you know how I would fix the problem if it was caused by NetBeans? Thanks for your suggestions so far.
All my main does is call the other classes. It doesn't display anything on the screen itself. Is that path with the image in the same folder as all the other files?
Ok tank you for your help its working now. I have another problem that I need help with. I am using a progress bar on one of the screens that pop-up. After the user enters a password, a welcome screen is displayed that welcomes the user to the program and shows how much the program has loaded. Instead of actually showing the progress, though, the outer frame is displayed then everything stops as the program loads, then all of the text, image, and progress bar appear. Here is basically my code
I have already checked out the tutorial for this and did not find anything that would help. Adding a button would be useless and a nuisance for the user. Any suggestions?