This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Image path location and the getResource() method Linux

 
Ranch Hand
Posts: 1397
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: 66208
250
  • 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: 1397
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: 21263
137
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: 1397
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: 21263
137
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: 1397
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: 3078
24
  • 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: 21263
137
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: 4322
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: 21263
137
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.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!