Results 1 to 4 of 4
- 12-19-2009, 01:02 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 43
- Rep Power
- 0
How to resize images to fit JLabel?
Hello, I need to load an image and use it in multiple places on my GUI but at different sizes.
So far I am just loading it with
Then I make a JLabel and size it to what ever size I need then use:Java Code:ImageIcon testIcon = new ImageIcon("images/testCard.jpg");
Then im left with a proper sized JLabel but only shows a portion of the image.Java Code:myJLabel.setIcon(testIcon);
How do I go about resizing this image to (in this case) shrink and resize to the size of the JLabel. I was looking through the ImageIcon java docs but didnt see anything about resizing.
Thanks for any tips.
- 12-19-2009, 01:20 AM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
> Then I make a JLabel and size it to what ever size I need then use:
Thats the reverse of what you should be doing. You should be resizing the image and then let the label size itself based on the image.
You can use image.getScaledImage(...) for the different size images.
- 12-19-2009, 01:29 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 43
- Rep Power
- 0
Thank you, worked great!
- 11-24-2010, 01:22 PM #4
1. Don't hijack an old thread.
2. Don't double post the same question.
Help: How to auto-resize the image icon to fit in the jlabel
db
Similar Threads
-
JScrollpane auto resize
By knuth in forum New To JavaReplies: 3Last Post: 09-29-2009, 10:12 PM -
how to resize an image
By marodia in forum AWT / SwingReplies: 2Last Post: 08-21-2009, 04:10 AM -
Image Resize
By jithan in forum New To JavaReplies: 4Last Post: 11-07-2008, 09:26 AM -
resize tabs in jtabbedpane
By osval in forum New To JavaReplies: 1Last Post: 08-02-2007, 03:02 AM -
Resize frame
By lenny in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 11:18 PM


LinkBack URL
About LinkBacks

Bookmarks