Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GIF image added to JPanel doesn't resize

 
Arun Bommannavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic