File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Android Security Essentials Live Lessons this week in the Android 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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Image fitting in JLabel
Similar Threads
Image text on mouseover
Can i add an image directly to a JLabel or JWindow?
Hide Image
Adding an Image to a Panel
Separator in JToolBar