gpt4 book ai didi

java - JGraphX 移动单元并保持边缘

转载 作者:行者123 更新时间:2023-12-02 08:12:29 25 4
gpt4 key购买 nike

我尝试在 JGraphX 中移动图形。我的第一次尝试是使用 setGeometry,但这也会移动整个坐标系及其原点。所以这对我来说不是一个选择,因为移动多个图表时有点棘手。

我的第二次尝试

Object[] ver = graph.getChildVertices(graph.getDefaultParent());
graph.moveCells(ver, 100, 100, false);

移动所有单元格。到目前为止一切顺利,但边缘的起点和终点改变了其位置。

移动单元格后:

After

在移动单元格之前,边缘具有正确的位置。

Before

那么如何将边缘的位置设置回正常的起点和终点?或者,我很欣赏将单元格移动到给定位置的任何其他方法。

编辑:似乎只有在我之前添加布局时才会发生这种行为。如果没有布局,移动单元将按预期工作。

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);

最佳答案

我通读了这个 JGraphx 的 api 文档,发现 xGraph 类中有趣的属性:

mxGraph.prototype.resetEdgesOnMove:

Specifies if edge control points should be reset after the move of a connected cell. Default is false.

我会尝试切换它,看看它在这种情况下是否有帮助。至少这会影响移动条件下的边缘行为。

关于java - JGraphX 移动单元并保持边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35063640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com