Reputation: 69
I would like to resize multiple imageIcons that I have attached to certain panels, but I'm not sure how to do that. After much research I've attempted to use .getScaledInstance but have had no luck, is that what I'm supposed to use? Since I define my panels outside of the main class but need to use the scaled instances of the images in multiple methods, would I add a line such as
image.getImage().getScaledInstance(30,30,whatever);
or would I need to do a different action?
Upvotes: 0
Views: 1278
Reputation: 347324
getScaledInstance
doesn't effect the original image, but instead returns a new instance of the image scaled to meet your parameters, make sure you are assigning the result to a variable, for example
image = image.getImage().getScaledInstance(30,30,whatever);
Then pass this to your what ever needs to use it
Beware, the quality of the operation is pretty poor, especially over a large range.
Take a look at
For details and ideas.
Upvotes: 4