Change dimension of image

Hi. I want to write small program that loads picture from file but not in original size but in size that I want.
(I think this small program would be helpful for my main goal and that is zoom in and zoom out loaded image.)

So far I have written program that displays loaded image with original size.

Try creating a program that zooms and pans with only the use of a mouse.

Here are some things to note in the code you posted:

After the first time, you are scaling an already scaled image when you set a new picture size. Over time the image quality will deteriorate. And for slightly more complicated reasons, there's the possibility of an OutOfMemoryError.

JPanel has FlowLayout by default, so the BorderLayout constraints when adding "+" and "-" are effectively ignored.

The validate() calls on the picture component are unnecessary since the component is not a Container and doesn't contain any children.

The Image returned by #getScaledInstance is a Toolkit image and is not guaranteed to be ready for drawing the first time you try to paint it. So you need to include a "this" as the ImageObserver parameter.

Java Code:

g.drawImage(picture,0,0,this);

Lastly, extending Component doesn't seem like a good idea. This introduces the possibility of flashing when painting, and you'll run into all the problems of trying to mix heavyweight components with lightweights should your program get anymore complicated.

After the first time, you are scaling an already scaled image when you set a new picture size. Over time the image quality will deteriorate. And for slightly more complicated reasons, there's the possibility of an OutOfMemoryError.

Lastly, extending Component doesn't seem like a good idea. This introduces the possibility of flashing when painting, and you'll run into all the problems of trying to mix heavyweight components with lightweights should your program get anymore complicated.

Thanks for your good suggestions.
Please give me some advices how to solve that problems and/or give me some useful links with examples so that I could see how it should be done.