I try to move a graph in JGraphX. My first try was to use setGeometry, but this moves also the entire coordinate system and its origin. So this is no option for me, because it is a bit tricky when moving several graphs.
My second try with
Object[] ver = graph.getChildVertices(graph.getDefaultParent());
graph.moveCells(ver, 100, 100, false);
moves all cells. So far so good, but the edges start and end points change its positions.
After moving the cells:
Before moving the cells, the edges have the correct position.
So how can I set the position of edges back to their normal start and endpoints? Alternatively, I appreciate any other approach to move cells to a given position.
EDIT: It seems like this behaviour only occurs, if I add a layout before. Without a layout, moving cells works as expected.
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
30);
Object v2 = graph.insertVertex(parent, null, "World!", 240, 150,
80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
}
finally
{
graph.getModel().endUpdate();
}
new mxHierarchicalLayout(graph).execute(graph.getDefaultParent());
graph.getModel().beginUpdate();
try
{
Object[] ver = graph.getChildVertices(graph.getDefaultParent());
graph.moveCells(ver, 100, 100, false);
}
finally
{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);