| Author |
GIF image added to JPanel doesn't resize
|
Arun Bommannavar
Ranch Hand
Joined: Jan 11, 2003
Posts: 53
|
|
I can add a GIF (or PNG) to a JPanel (see code below) but the image doesn't rescale automatically. I need to have this image rescale when the JPanel is resized. I appreciate any suggestion. Regards Arun
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
Well, the problem is that you are adding a JLabel to a JPanel and chances are the JLabel isn't resizing. So its not really the images. If you are simply trying to add an image to a JPanel (as a background image) then you should do it something like what is written here. If you still need it on a JLabel then you need to be sure your layout manager is resizing your JLabel correctly.
|
 |
Arun Bommannavar
Ranch Hand
Joined: Jan 11, 2003
Posts: 53
|
|
Originally posted by Gregg Bolinger: Well, the problem is that you are adding a JLabel to a JPanel and chances are the JLabel isn't resizing. So its not really the images. If you are simply trying to add an image to a JPanel (as a background image) then you should do it something like what is written here. If you still need it on a JLabel then you need to be sure your layout manager is resizing your JLabel correctly.
I finally ended up overriding the paintComponent as follows: works well. Regards Arun
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Please keep paintComponent protected. It's unnecessary to have it be public. I already updated the FAQ about this. [ August 01, 2008: Message edited by: Rob Prime ]
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: GIF image added to JPanel doesn't resize
|
|
|