• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Image does not load on JPanel, no errors  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I tested a class I created to load images and that works fine. When calling the class with 'new LoadImage("imagename.gif");' from another class it fails.
I really have no idea why..

Thank you ahead for your help.

 
Sheriff
Posts: 21461
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should start using resources. Check out Class.getResource and ClassLoader.getResource. Moving to our GUI forum.
 
Rancher
Posts: 2941
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, there is no need to create a custom component to do this. Just use a JLabel with an Icon.

I suggest you read the Swing tutorial for working example. Start with the section on "How to Use Icons". And if you really must to custom painting then read the section of custom painting. YOu should not be extending Component since that is an AWT component and you should only use Swing components in a Swing application.

 
Deborah Larsson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:You should start using resources. Check out Class.getResource and ClassLoader.getResource. Moving to our GUI forum.


Thanks for the tip, but that was not helpful for solving the problem.
 
Deborah Larsson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Camick wrote:Also, there is no need to create a custom component to do this. Just use a JLabel with an Icon.

I suggest you read the Swing tutorial for working example. Start with the section on "How to Use Icons". And if you really must to custom painting then read the section of custom painting. YOu should not be extending Component since that is an AWT component and you should only use Swing components in a Swing application.



I am not sure why you advise me to use a JLabel for this. Easier than adding to a panel with no undesirable side-effects? It is a normal image without text. It also worked on itself, via it's main function, so the code itself was ok.
I solved the issue now. It did not show because by default it used a grouplayout manager when it was created with the GUI designer in Netbeans . In the end I had to open it via an external editor to delete the group layout code. Then via the designer it finally accepted the change to a borderLayout. and did the trick.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Deborah Larsson wrote:
I am not sure why you advise me to use a JLabel for this. Easier than adding to a panel with no undesirable side-effects? It is a normal image without text.


Yes, the code to do this with a simple JLabel/ImageIcon is a lot simpler than what you're currently doing.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!