Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ImageIcon not showing Ubuntu

 
Dwayne Brown
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Dwayne Brown
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to Use Icons

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.
 
Dwayne Brown
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check out what Pete said. that might be what you want
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic