Hi Everyone,\nIs there a possible way to add mouselisteners on mxGraph( Jgraphx) and verify which vertex/edge has been clicked on?

\n

thank you,

asked 14 Aug '11, 15:04

P2del's gravatar image

P2del
33211
accept rate: 12%


I found graphComponent.getGraphControl().addMouseListener(new MouseAdapter()). However is there any possible way to get the vertex/edge's id that has been clicked probably?

\n

Thank you

link

answered 14 Aug '11, 16:37

P2del's gravatar image

P2del
33211
accept rate: 12%

edited 14 Aug '11, 16:41

Ok I got it, in this example "On" is the user value for the vertex.\ngraphComponent = new mxGraphComponent(graph);\n graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {\n @Override\n public void mouseClicked(MouseEvent e) {

\n
                      Object cell = graphComponent.getCellAt(e.getX(), e.getY());\n                if(cell != null && cell instanceof mxCell){\n                   System.out.println("Cell selected");\n\n                   if(((mxCell)cell).getValue().toString().equals("On")){\n                      System.out.println("My Cell selected");\n                   }\n                                       }\n                }\n
link

answered 15 Aug '11, 08:15

P2del's gravatar image

P2del
33211
accept rate: 12%

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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

Tags:

×194
×11

Asked: 14 Aug '11, 15:04

Seen: 3,587 times

Last updated: 15 Aug '11, 08:15