I've created a class which paints an image on a button, working fine. However when I set the boundaries of the button so the size/position changes, the image gets stretched and basically looks messed up. I've tried calling repaint() but to no avail. Is there some way I can fix this? Cheers
I'm afraid you're contradicting yourself. In your first post you said the images stretches, which is what you would expect when the button resizes. In your last post you say the image doesn't get repainted with the new dimensions.
What's the problem, and how do you want it to behave?
Joined: Sep 15, 2009
I want the image to scale according to the component size rather than become distorted.
E.g. I have an image 200x200px
If I create a new button that is 200x200 and paint the image, it looks fine.
If I create a new button that is 100x100 and paint the image, it looks fine and the image scales down.
If I create a new button that is 100x100, then resize that button using setBounds to 200x200, the image doesn't scale, it stretches and looks bad. I need a way of repainting that image on the resized button.
If you want the image to scale in a colinear fashion, you have to compute the new height and width.
By the way, there's absolutely no need to siubclass JButton and override paintComponent just to draw an image. You can set an Icon to a JButton instead. The icon's paintIcon can take care of the scaling, and if the size of the button is independent of its preferredSize, the icon can return 0 for its width and height.
There are no new questions, but there may be new answers.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com