I need to get the new position of a vertex after moving (by dragging) and I wrote the code as below :

graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {\n        @Override\n        public void mousePressed(MouseEvent e) {\n            //do something (it works and I can get the identifier of vertex.)\n        }\n        @Override\n        public void mouseReleased(MouseEvent e) {\n            //get the new position after moving\n            //but mouseReleased() is not being called\n        }\n}\n

How can I solve this problem? Or Is there another way to achieve this? I really need helps, thank you.


P.S mouseReleased only worked when I clicked on a vertex.

asked 19 Jan '12, 04:16

chevalierz's gravatar image

accept rate: 0%

edited 29 Jan '12, 08:56

David's gravatar image


Are you using DnD for the move operation? I think during DnD, only the initial mousePressed is fired. Try using the MOVE_CELLS event instead, eg.

graph.addListener(mxEvent.MOVE_CELLS, new mxIEventListener()\n{\n  public void invoke(Object sender, mxEventObject evt)\n  {\n    Object[] cells = (Object[]) evt.getProperty("cells");\n    Double dx = (Double) evt.getProperty("dx");\n    Double dy = (Double) evt.getProperty("dy");\n\n    System.out.println("Cells moved: "+cells.length+" "+dx+" "+dy);\n  }\n});\n

answered 19 Jan '12, 20:54

Gaudenz's gravatar image

accept rate: 39%

Thank you Gaudenz!!!! I applied it to my code and it works!! \nYour answer helps me a lot :)

(29 Jan '12, 07:03) chevalierz
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 19 Jan '12, 04:16

Seen: 3,997 times

Last updated: 29 Jan '12, 08:56