aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Image fitting in JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image fitting in JLabel" Watch "Image fitting in JLabel" New topic
Author

Image fitting in JLabel

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
Is there a way to make an image fit the size of a JLabel?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Sure, scale it. You can scale it to just fit in the given bounds or scale it to just fill the space. Make a new BufferedImage the size of the JLabel, use AffineTransform to scale the source image and draw the scaled source into the new image with Graphics2D drawRenderedImage.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Image fitting in JLabel