I am developing an application that drag and scale image in Jpanel.
The image is stored inside a JLabel.
But when i am adding the MouseMotionListener to the panel, then whole window is dragging and when i am trying to add MouseMotionListener to I can't select the sides of image to scale it.
So can i directly add MouseMotionListener to BufferedImage?
With any component I add MouseMotionListener, it don't allow me to select sides of image. sides means all direction for to scale image.
Window :
addMouseListener(handler);
addMouseMotionListener(handler);
JLabel :
label.addMouseListener(new MouseHandler());
label.addMouseMotionListener(new MouseHandler());
Here MouseHandler
is a class defined for various operation like mousePressed
, mouseDragged
, mouseMove
, etc.
Any idea why it is behaving like that?
The BufferedImage
is a class that supports general image manipulation. It can be used equally from interactive programs with a graphical user interface, and from non-interactive batch processing programs with no user interface. Having a mouse listener on something that is not used in a GUI does not make sense, so you can't add a MouseMotionListener
to a BufferedImage
.
You should add the listener to the GUI component that is showing the image instead.