// if you are using an mxEditor instance)
graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener()
{
public void invoke(Object sender, mxEventObject evt)
{
graphComponent.validateGraph();
}
});
// Initial validation
graphComponent.validateGraph();