This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript 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
Ranch Hand
Posts: 15304
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
Posts: 20822
68
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 ]
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!