Vertex label in JUNG graph visualization

女生的网名这么多〃 提交于 2019-11-28 11:25:40

You need to call a label transformer for your vertex/edge:

        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());

This is something you'd find pretty often in the samples. It uses the toString() method of your vertex class to specify the label.

A slightly more involved example:

        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<MyEdge, String>() {
            public String transform(MyEdge e) {
                return (e.toString() + " " + e.getWeight() + "/" + e.getCapacity());
            }
        });

You don't need to iterate over the edges; the EdgeLabelTransformer or VertexLabelTransformer will label your edges as and when their properties are updated, and the VisualizationViewer will update them on the fly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!