File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image fitting in JLabel

 
Barry Brashear
Ranch Hand
Posts: 303
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to make an image fit the size of a JLabel?
 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic