Search code examples
javajgraphtjgraphx

How to disable visual graph (interconnection) modifications in JGraphT/JGraphX?


I have visualized relationships in my program with JGraphT's JGraphXAdapter.

Unfortunately, I need to allow user only visual modifications of the graph, i.e. moving/resizing nodes. But he still can edit something, despite the fact I disabled everything I found:

setLayout(new BorderLayout());
        add( 
            new mxGraphComponent(
                jgxAdapter = new JGraphXAdapter<Corpus, CorporaDirectory.CorporaGraphEdge>(
                    CorporaDirectory.getInstance().getCorporaGraphModel()
                ) {{
                    setCellsDeletable(false);
                    setCellsCloneable(false);
                    setCellsEditable(false);
                    setCellsDisconnectable(false);

                    setConnectableEdges(false);
                    setVertexLabelsMovable(false);
                    setSplitEnabled(false);

                }}
            ) 
        );

specifically user still can add new edges:

enter image description here

UDPATE

If I set setEnablled(false) to mxGraphComponent then I get totally frozen graph.


Solution

  • Try using mxGraphComponent.setConnectable(false), it should disable connection handler in the graph component.