size of image icons in button

Hi experts,

is there any way to set all my images on the buttons to a certain size?

thanks
SamooramadAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
Image i = icon.getImage();
Image scaled = i.getScaledInstance(width, height, Image.SCALE_SMOOTH);
ImageIcon resized = new ImageIcon(scaled);
0
 
CEHJCommented:
Haven't we been this way before ? ;-)
0
 
objectsCommented:
you'll need to resize them before assinging them to your buttons.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
CEHJCommented:
The last idea was to scale them before adding them i seem to remember ;-)
0
 
SamooramadAuthor Commented:
I dont know CEHJ.. I tend to forget :)
0
 
objectsCommented:
the above code will achieve what you require
0
 
SamooramadAuthor Commented:
ok will get back to you

hey if you guys have time to kill help me out with my printing question :)
0
 
objectsCommented:
> hey if you guys have time to kill

I wish :)
0
 
SamooramadAuthor Commented:
Image i = icon.getImage();

objects, got an error with this line..

 icon is not public in java.awt.Frame; cannot be accessed from outside package at line 33, column 13
I placed this line with my declarations..do I need to move it?
0
 
SamooramadAuthor Commented:
>>I wish :)

well :) ... anytime you can spare is always appritiated
0
 
objectsCommented:
replace icon with the variable name of your (inscaled) ImageIcon:
0
 
objectsCommented:

ImageIcon icon = new ImageIcon(...
Image i = icon.getImage();
Image scaled = i.getScaledInstance(width, height, Image.SCALE_SMOOTH);
ImageIcon resized = new ImageIcon(scaled);

0
 
SamooramadAuthor Commented:
worked like a charm
thaaaaaaank yoooooouu :)
0
 
objectsCommented:
no worries :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.