resizing and redrawing

S

semi

I'm trying to redraw an image after I resize the window, but the image
disappears everytime I resize. How do I scale the image to the size of
the window? Or, another way you can look at it is: I click points onto
a screen and when I resize the window, I want the points not to be
where they were before, but scaled according to the window size. Is
there a function that can just handle resizing of the windows, or is
everything going to go to the repaint( ) method?
 
S

semi

Mon, 14 Jan 2008 07:35:38 -0800 (PST), /semi/:
Thanks for the reply, but it didn't work. I'm using ImageIcon and not
Image. I need to use ImageIcon.

You could try using ImageIcon.getImage() [1]:

ImageIcon icon;
...
public void paint(Graphics g) {
Image theImg = icon.getImage();
g.drawImage(theImg, 0, 0, getWidth(), getHeight(), this);
...

[1]
<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ImageIcon.html#ge...()>



Yes, that works!!! Thank you both for your help.
 
R

Roedy Green

Thanks for the reply, but it didn't work. I'm using ImageIcon and not
Image. I need to use ImageIcon.

you can extract the Image from an ImageIcon.
the additional parts are just to arrange an automatic MediaTracker.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top