我实现了一些图表算法,我想展示它们。我使用了Jung 2.0
我想为节点添加名称。我设法如何写边缘,但我也想显示一个节点的名称。
这是我的代码:
Graph<Integer, String> graph3 = new DelegateForest<Integer, String>();
graph3.addVertex(1);
graph3.addVertex(2);
graph3.addVertex(3);
graph3.addEdge("RAD-A", 1, 2);
graph3.addEdge("RAD-B", 1, 3);
Layout<Integer, String> layout3 = new TreeLayout<Integer, String>((Forest<Integer, String>) graph3);
VisualizationViewer<Integer, String> vv3 = new VisualizationViewer<Integer,String>(layout3);
Transformer<String, String> transformer3 = new Transformer<String, String>() {
@Override
public String transform(String arg0){
return arg0;
}
};
vv3.getRenderContext().setEdgeLabelTransformer(transformer3);
transformer3 = new Transformer<String, String>() {
@Override
public String transform(String arg0){
return arg0;
}
};
final DefaultModalGraphMouse<String,Number> graphMouse3 = new DefaultModalGraphMouse<String,Number>();
vv3.setGraphMouse(graphMouse3);
graphMouse3.setMode(ModalGraphMouse.Mode.PICKING);
JFrame frame3 = new JFrame("Pas 3");
frame3.getContentPane().add(vv3);
frame3.pack();
frame3.setSize(350, 300);
frame3.setVisible(true);
答案 0 :(得分:2)
你几乎就在那里......你需要做与边缘一样的事情......
对于边缘你做了类似的事情:
vv3.getRenderContext().setEdgeLabelTransformer(transformer3);
对于节点是相同的...你需要 setVertexLabelTransformer
将此细分添加到您的代码中..
Transformer<Integer, String> transformer = new Transformer<Integer, String>() {
@Override
public String transform(Integer arg0) {
return arg0.toString();
}
};
vv3.getRenderContext().setVertexLabelTransformer(transformer);
您需要调整通用映射以保存Integer,String ...
在esd你会得到像这样的东西