如何在JUNG图形可视化中使用自定义顶点标签?
我正在关注Jung 2.0 教程,在那里我发现setVertexLabelTransformer()
可以用来标记顶点,但据我所知,这些标签不能自定义。
例如,下面的代码产生三个顶点,顶点标签为 1,2,4:
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import java.awt.Dimension;
import javax.swing.JFrame;
public class SimpleGraphView {
Graph<Integer, String> g;
public SimpleGraphView() {
g = new SparseMultigraph<Integer, String>();
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)4);
}
public static void main(String[] args) {
SimpleGraphView sgv = new SimpleGraphView();
Layout<Integer, String> layout = new CircleLayout(sgv.g);
layout.setSize(new Dimension(800,800));
BasicVisualizationServer<Integer,String> vv =
new BasicVisualizationServer<Integer,String>(layout);
vv.setPreferredSize(new Dimension(850,850));
JFrame frame = new JFrame("Simple Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
}
如何添加“q0”之类的标签?