• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to insert .gif image inside a panel

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
non animated images ..i.e with .png or .jpg extension ..
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic