Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to insert .gif image inside a panel  RSS feed

 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to insert a .gif image in a panel. I am using following code :

java.net.URL imageURL = getClass().getClassLoader().getResource("images/loading.gif");
ImagePanel loading = new ImagePanel(new ImageIcon(imageURL).getImage());
this.jPanel1.add(loading);

Using this if I insert normal image it displays but if I changes it to loading.gif it doesn't ...
What is the issue ? and how to fix it ?

Thanks,
 
Alfred Peterson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i cant give you the exact answer but surely i must know that if you want to use an existing PSD ,for that you must have at least PSD extended and also change the format to AV ..this might help you out ...thanks
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you mean by normal image?
 
Rite Sara
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
non animated images ..i.e with .png or .jpg extension ..
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't support animated images out of the box. You'll need to do the animation yourself, or find a library to do it for you.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Java doesn't support animated images out of the box. You'll need to do the animation yourself, or find a library to do it for you.


Works in JDK6 on XP when you add the ImageIcon to a JLabel.

It probably won't work in this example since it looks the the OP is trying to draw the image directly onto a JPanel.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
Rob Prime wrote:Java doesn't support animated images out of the box. You'll need to do the animation yourself, or find a library to do it for you.


Works in JDK6 on XP when you add the ImageIcon to a JLabel.

It probably won't work in this example since it looks the the OP is trying to draw the image directly onto a JPanel.


Depends on how the image is loaded. ImageIO.read(...) returns a BufferedImage, so animation isn't supported. An image loaded with Toolkit animates just fine.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on how the image is loaded. ImageIO.read(...) returns a BufferedImage, so animation isn't supported. An image loaded with Toolkit animates just fine.


Interesting to know, although I'm lazy and would always use the ImageIcon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!