java - JUNG:按顺序放置树节点

标签 java tree visualization jung

向我的 DelegateTree 添加节点时,它们在视觉上不会按照我添加的顺序显示。 我一直在寻找解决方案,但还没有找到任何东西。 有谁知道如何更改此设置吗?

提前致谢!

编辑:我的代码

/**
 * Generate a visualization of the decision tree.
 * 
 * @param tree
 *            The decision tree
 * @return A component to be placed inside a JPanel
 */
public static GraphZoomScrollPane generateTree(Tree tree,
        GraphicalUserInterface gui) {

    /* Create a new tree */
    DelegateTree<Node, Edge> graphTree = new DelegateTree<Node, Edge>();

    /* Add all nodes and vertices to the tree */
    graphTree.addVertex(tree.getRoot());
    addChildren(tree.getRoot(), graphTree);

    /* Create the visualization */
    DynamicTreeLayout<Node, Edge> treeLayout = new DynamicTreeLayout<Node, Edge>(graphTree, 100, 100);
    VisualizationViewer<Node, Edge> vv = new VisualizationViewer<Node, Edge>(
            treeLayout);
    vv.setDoubleBuffered(true);
    vv.setBackground(Color.WHITE);
    vv.getRenderContext().setEdgeLabelTransformer(
            new ToStringLabeller<Edge>());
    vv.getRenderContext().setEdgeShapeTransformer(
            new EdgeShape.Line<Node, Edge>());
    vv.getRenderContext().setVertexLabelTransformer(
            new ToStringLabeller<Node>());
    vv.getRenderer().getVertexLabelRenderer()
            .setPosition(Renderer.VertexLabel.Position.S);

    vv.addGraphMouseListener(new ClickNode(gui, vv));

    final DefaultModalGraphMouse<Node, Edge> graphMouse = new DefaultModalGraphMouse<Node, Edge>();

    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    vv.setGraphMouse(graphMouse);

    final GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);

    return gzsp;
}

/**
 * Recursively add all nodes and edges to the tree.
 * 
 * @param node
 *            The parent node
 * @param tree
 *            The tree visualization
 */
private static void addChildren(Node node, DelegateTree<Node, Edge> tree) {
    for (int i = 0; i < node.getChildren().size(); i++) {
        tree.addChild(new Edge(node.getChildren().get(i).getEdgeLabel()), node, node
        .getChildren().get(i));
        addChildren(node.getChildren().get(i), tree);
    }
}

最佳答案

使用 DelegateTree 的底层实现,根据顶点的自然顺序 (*Sorted*Graph) 对其顶点进行排序,或者使用插入顺序 (*Ordered*Graph)。

关于java - JUNG:按顺序放置树节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10215718/

相关文章:

python - Tensorflow - 可视化预训练网络的学习过滤器

matlab - 在 matlab 中读取 .ply 文件

用于动态可视化的 Java 图形库

java - Apache 服务器上的 TLS

java - 以编程方式设置 textView 颜色

algorithm - 如何为最小生成树增加弹性?

c++ - 在节点中使用原始指针,在树中使用 unique_ptr

java - 搜索未排序树的特定节点

java - SSL异常,套接字异常: Connection reset from Apache HttpClient

java - 由于找不到 ALPN 处理器,与 WireMock 的集成测试失败