1

我正在使用 jgraphx 1.12.0.2,并且正在尝试从代码中重新排列图形的顶点。代码看起来像这样:

Object[] roots = graph.getChildCells(graph.getDefaultParent(), true, false);
graph.getModel().beginUpdate();
for (int i = 0; i < roots.length; i++) {
    Object[] root = {roots[i]};
    graph.moveCells(root, i * 10 + 5, 50);
    /* these two lines were added because I thought they might help with the problem */
    /* with or without them, the result is the same */
    graph.getView().clear(root, true, true);
    graph.getView().validate();
 }
 graph.refresh();
 graph.getModel().endUpdate();

当然,问题是细胞没有移动到指定的位置。可能是什么问题呢?

谢谢!

4

1 回答 1

0

您不需要刷新、清除或验证。如果您选择正确的操作,一切都会为您完成。值得完整阅读用户手册的第 2 部分,它解释了核心模型 API 方法。

在这种情况下,您希望model.setGeometry()begin/end update. 但请确保不要使用从 getGeometry 获得的几何对象,您必须使用新对象或从 getter 中复制的对象。就地更改模型对象会破坏撤消模型。

于 2013-04-29T07:59:03.260 回答