• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

ImageIcon not showing Ubuntu

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check out what Pete said. that might be what you want
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic