• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Image path location and the getResource() method Linux

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

when I getResources() from the package below in Linux I get an image correctly

but when I try to get it from the package below it doesnt launch an error but the image is not displayed.

 
Marshal
Posts: 69410
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the @Override annotation and give paintComponent() protected access, not public. Please single‑space your code; the many empty lines don't make it any easier to read.

Write super.paintComponent(g); first. This is important; at present you are simply wiping any images away.
If that doesn't help, please show us the directory structure where the image and the XXX.class file corresponding to this are.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made the changes commented in the code and it still doesn't get the images.

I call it from the Swing presentation menu with this code;


These are the requested paths



 
Saloon Keeper
Posts: 22111
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using double-slashes between your resource path levels?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why are you using double-slashes between your resource path levels?


With a single-slash, the result is exactly the same one.
 
Tim Holloway
Saloon Keeper
Posts: 22111
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Angus Ferguson wrote:

Why are you using double-slashes between your resource path levels?


With a single-slash, the result is exactly the same one.



So why use double-slashes?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So why use double-slashes?



It has not effect in file paths in fact it is treated as a single path, with Linux for me is more stylish...I find value on it.

 
Rancher
Posts: 3182
29
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't solve your problem but you should NOT be doing I/O in the paintComponent() method.

A painting method is for painting only. You do not want to keep reading the image every time the method is invoked.

The image should be read in the constructor of your class so it is available for painting whenever the component needs to be repainted.
 
Tim Holloway
Saloon Keeper
Posts: 22111
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know that the classloader is going to repeatedly do I/O, but it's still worth it to create the Image object once and cache it. Even if the image data comes straight from RAM, there's no virtue in repeating the overhead to convert it.
 
Rancher
Posts: 4576
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't the leading slash mean "get this resource from the top of the classpath"?

So that will be searching for the resource in <classpath_root>/images/CHL_predictions_next_day.png rather than <classpath_root>/org/marineDigitalJournal/presentation/swing/images/CHL_predictions_next_day.png.

The other one works presumably because the code is something like:

?
 
Tim Holloway
Saloon Keeper
Posts: 22111
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Angus Ferguson wrote:

So why use double-slashes?



It has not effect in file paths in fact it is treated as a single path, with Linux for me is more stylish...I find value on it.



I don't. In fact, I had to double-check to see if there weren't consequences to the extra clutter.

You might as well have coded "/./marineDigitalJournal/./presentation/../presentation/./swing/./images/../images/./predictions_high_CHL_locations.png"

Redundant syntactic lint is only going to make people waste time on figuring out something unrelated to the main problem.

If you're using the URL format like "http://"; you're failing to understand that that particular set of double slashes has a specific meaning and isn't just for decoration. Using one slash or 3 slashes instead of 2 slashes changes the path location, not just the appearance.
 
Have you no shame? Have you no decency? Have you no tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic