> I need to display only a particular portion of a big gif image in a
> fixed-size square component; the coordinates of the visible square to
> display are to be determined at runtime. What image component should I
> use? I am only familair with the Swing label's setIcon() method, but it
> doesn't let me choose what part of the image I want to display.
a) Use e.g. any subclass of Image, e.g. BufferedImage, to hold the
image, and a JPanel to display it. Use e.g.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.aw
t.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.imag
e.ImageObserver)
to draw the image.
In order to pull this successful off, you need to familiarize yourself
with the general way drawing/painting in Swing happens.
b) Load the Image into a BufferedImage. Then use
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#getSub
image(int,%20int,%20int,%20int)
to create a sub-image. Create an ImageIcon from the BufferedImage and
display that ImageIcon in a JLabel.
c) Use a scrollpane, turn the scrollbars of, and set the viewport to the
parts of the image you want to display.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Di Pascale - 24 Jan 2005 17:54 GMT
You've been of great help... thanks a lot!!! I'll try to get the hang of
all the possibilities you've illustrated.
>> I need to display only a particular portion of a big gif image in a
>> fixed-size square component; the coordinates of the visible square to
[quoted text clipped - 23 lines]
>
> /Thomas