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.
OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Dwayne Brown
Greenhorn
Joined: Jan 16, 2012
Posts: 13
posted
0
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.
Also note that the forward slash / as a path separator applies to both Windows and Linux. Only the backslash \ is Windows-only.
Moving to the GUis section, where we normally discuss Swing stuff.
luck, db
There are no new questions, but there may be new answers.
Dwayne Brown
Greenhorn
Joined: Jan 16, 2012
Posts: 13
posted
0
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.
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4089
posted
0
check out what Pete said. that might be what you want
Dwayne Brown wrote:I know that is not practical for deployment. I just need to know how to pull the copied images from the resource folder.
Too much trouble to go through the tutorial I gave you a link for, huh?
Dwayne Brown
Greenhorn
Joined: Jan 16, 2012
Posts: 13
posted
0
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 agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.