This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 21370
91
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: 2911
18
  • 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.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!