Re: Drawing an Image in a JPanel




"Andrew Thompson" <andrewthommo@xxxxxxxxx> wrote in message news:1156943866.818172.190100@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
john wrote:

> ... using a JLabel would be 'wrong'. JLabel's
> are good for 'get an image and show it' - but if
> you need anything more than that (zooming/resizing,
> cropping, flipping, filtering, color palette changing..)
> a JLabel simply gets in the way.
...
> Put first lets get precise on your requirements for this
> project. What does it do?
...
That's exactly what I am aiming for - An Image editor that can perform
cropping, resizing, and flipping. What would be the best approach?

OK. While I am sure that a JLabel is the wrong component
for this use, I am ot entirely sure of the best design/approach,
and am hoping that others will jump in with further advice on
that matter.

It's been a while, but I think something like a plain old JPanel will do the trick. You just need a surface to draw upon. If you want to get a bit fancy, you can wrap the JPanel in a JScrollPane to let the user manipulate images that are bigger than her screen. This is definitely an issue if you allow the user to zoom into the image.

You'd also probably want to keep an internal representation of the picture, to facilitate saving to disk, or doing certain types of manipulation such as supporting undo and redo. I.e. be sure to seperate the model data from its representation on screen.

- Oliver

.