When a user clicks on a vertex i want to set visible a panel that displays (some of) the vertex's properties.


Which event (mxEvent) is triggered when someone clicks on a vertex, so as to add a new mxIEventListener on my mxGraphComponent?


addListener(mxEvent.????, new mxIEventListener() { .. });




(mxEvent.SELECT did not work)

asked 29 Mar '11, 05:16

koula's gravatar image

accept rate: 0%

edited 29 Mar '11, 05:19



I just had the same problem as you and managed to solve it for me (with help from the documentation). The clue is to use the Selection model - and the Event CHANGE.\n

\n      m_graph = new mxGraph();\n      m_graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxIEventListener() {

     @Override\n     public void invoke(Object sender, mxEventObject evt) {\n\n     }\n\n  });\n

\nThe graph generation was omitted for brevity.


This works for me. Hope for you too :)


answered 29 Mar '11, 06:21

Patrick's gravatar image

accept rate: 100%

edited 29 Mar '11, 06:39

Where did you place this code for it to work?

(10 Aug '11, 21:24) gravyplaya

Basically, I placed it in the Constructor for the Swing component that contains the graph component. You of course will need to use an mxGraphComponent with the mxGraph (now with above listener attached) as the model...\nDoes that help or could you be more specific?

(10 Aug '11, 22:29) Patrick

Just to elaborate Patricks answer:

    // Handle only mouse click events\n    graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {\n        @Override\n        public void mousePressed(MouseEvent e) {\n            Object cell = graphComponent.getCellAt(e.getX(), e.getY());\n            System.out.println("Mouse click in graph component");\n            if (cell != null) {\n                System.out.println("cell=" + graph.getLabel(cell));\n            }\n        }\n    });\n

(use e.getButton() to detect left or right click)\nor

    // Handle general click events (by mouse selection or Ctrl+A)\n    graph.getSelectionModel().addListener(mxEvent.CHANGE, new mxIEventListener() {\n        @Override\n        public void invoke(Object sender, mxEventObject evt) {\n            System.out.println("evt.toString() = " + evt.toString());\n            System.out.println("Selection in graph component");\n            if (sender instanceof mxGraphSelectionModel) {\n                for (Object cell : ((mxGraphSelectionModel)sender).getCells()) {\n                    System.out.println("cell=" + graph.getLabel(cell));\n                }\n            }\n        }\n    });\n

The second snippet (suggested by Patrick), is better since it handles the case of multiple cells being selected.


answered 29 Mar '11, 12:51

eisbaw's gravatar image

accept rate: 31%

edited 08 Apr '11, 13:01


thanks for your feedback. that is what i did, and works.

(10 Apr '11, 08:02) koula

can I hava a complete source code wherein we have a cliquable vertex?

(28 Dec '12, 03:14) sfoyang
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: 29 Mar '11, 05:16

Seen: 8,959 times

Last updated: 10 Apr '13, 07:50