gcode
gcode

Reputation: 2989

Java Swing: Resize JMenuItem's icon, either automatically or programatically?

It seems that JMenuItems don't automatically resize any image icon that's assigned to them, and from what I can tell, there isn't a property that makes them automatically do that, either.

Is anyone aware of a way that I can programatically resize the Icon for a JMenuItem? It seems like the Icon object is lacking functionality as it is, unless there's some other function that can actually deal with Icon objects.

Upvotes: 2

Views: 931

Answers (2)

StanislavL
StanislavL

Reputation: 57421

You can use Image class' method public Image getScaledInstance(int width, int height, int hints) to scale to desired size.

Upvotes: 1

corsiKa
corsiKa

Reputation: 82589

Extend the class and override it's paint method to resize the image before painting.

Upvotes: 1

Related Questions