Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image fitting in JLabel  RSS feed

 
Barry Brashear
Ranch Hand
Posts: 303
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!