Hello all. I am trying to display in image in my swing application. I can add images just fine in Windows but not in Ubuntu. How can I accomplish this? Usually I add the code down below to add in windows.
That is a generic example but it does work. What is the equivalent in Linux
A similar path on Linux might be "/images/logo.png", but chances are that file won't exist (unless somehow you put it there).
A common approach is to include any icon images in your classpath (like your application's jar file), and then use the ClassLoader's getResourceAsStream(String) method to read the icon as a byte array. Then use the ImageIcon(byte) constructor to create your icon.
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Do you know of any tutorials for that in a Linux perspective? All books I have learned from come from a Windows or Mac point of view. They work but what you have described is new to me. Thank you for your help and response.
I figured out how in eclipse if you add the image to your project you can find out the full path no matter what platform you are on. The steps I took was right click on project and select to add a source folder. I named mine resources. Then copy pictures into the source folder. If you right click the picture and go to properties it will display the full path. You can copy and paste path into your ImageIcon. I know that is not practical for deployment. I just need to know how to pull the copied images from the resource folder. I tried the exact path from the resource folder and the images do not show.
Darryl, I appreciate your response and I am going through that. I was not ignoring your suggestion but was following other examples and was eager to share what I found. All responses are greatly appreciated!
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss