1

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?

Gerret
  • 2,948
  • 4
  • 18
  • 28
Java Curious ღ
  • 3,622
  • 8
  • 39
  • 63
  • 1
    Why you don't put the MouseMotionListener at the JLabel? – Gerret Aug 22 '13 at 10:53
  • @Gerret - i have added it to JLabel but it's not work because when i am trying to select any corner or direction of image it will not work because i have applied it on JLabel and Jlabel in into JPanel so where the co-ordinate of JLabel is i don't know. – Java Curious ღ Aug 22 '13 at 11:00
  • What about to put the Image directly on the Panel... – Gerret Aug 22 '13 at 11:01
  • And another question is actully enough place to resize the picture grapically. What about if you only use a input field? And display than the resized picture at the Label? – Gerret Aug 22 '13 at 11:06
  • @Gerret - when i am trying to add Image Directly to JPanel it shows me an error. i have write code : `JPanel j; j.add(a);` here a is instance of BufferedImage. it shows error that a should be component or add method take component as an argument. – Java Curious ღ Aug 22 '13 at 11:12
  • okok your right and what is with my other solution or you dont like that :) – Gerret Aug 22 '13 at 11:14
  • that actually i don't understand, will you elaborate it ? – Java Curious ღ Aug 22 '13 at 11:14
  • I may will help you... xD But thats a lot easyer than to make it graphically movable or dont you think so? Just use a inputbox where the user is able to put the size of the picture and than resize it and show it – Gerret Aug 22 '13 at 11:17
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35995/discussion-between-user2659972-and-gerret) – Java Curious ღ Aug 22 '13 at 11:18
  • For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Aug 22 '13 at 13:25

1 Answers1

1

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.

Joni
  • 108,737
  • 14
  • 143
  • 193