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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
All Courses

From novice to tech pro — start learning today.