It's not a secret anymore!
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image fitting in JLabel" Watch "Image fitting in JLabel" New topic

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.
I agree. Here's the link:
subject: Image fitting in JLabel
It's not a secret anymore!