mxGraph editor - fire an event when a node is created

1.9k views Asked by At

I'm playing with the sample mxGraph editor that comes with JGraph. I have a method which I'd like to be called every time a new node is created. Do you know how to do this?

I have a feeling it has something to do with mxGraphComponent, but I couldn't figure out how to do it.

1

There are 1 answers

0
Frodo Baggins On BEST ANSWER

Have a look at the API docs of the mxGraph class. It fires a number of granular events to specify what changes have occurred. You are most likely interested in mxEvent.CELLS_ADDED. So add a listener with:

graph.addListener(mxEvent.CELLS_ADDED, myHandler);

where myHandler implements the mxIEventListener interface that requires the invoke method to be implemented (your method that gets called when the event is fired).