Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

loading gifs etc

  Asked By: Lorraine    Date: Jul 10    Category: Java    Views: 673
  

I want a series of gifs to be loadable onto a panel....is there any
(relatively simple) way of getting these to resize automatically so
that they fit within the panel.

each gif is in an image icon...but when you use "preferred size" or
anything like that, it simply resizes the EDGES of the image...in
other words it just clips the image, which is not what I am after!

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Khadeeja Malik     Answered On: Jul 10

Check out this URL

www.ecs.umass.edu/.../
drawingImages.html

Its from the 2D graphics section of the Java tutorial.

In the example displays an image  on an applet and scales it. In your
case, you want to display an image on a JPanel (I'm assuming that you
are using Swing but it should work if you are using the Panel object
from AWT).

import javax.swing.*;

public class ImagePanel extends JPanel {
Image image;

...

image = getImage(getCodeBase(), "../images/rocketship.gif");

...

public void paint(Graphics g) {
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
}

The getWidth() and getheight() should return the width and height of
the JPanel.

 
Didn't find what you were looking for? Find more on loading gifs etc Or get search suggestion and latest updates.




Tagged: