This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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!