2
我創建使用JGraphT庫圖:如何在添加頂點後更新JGraphT視圖?
g = new ListenableUndirectedWeightedGraph <String, MyEdge>(MyEdge.class);
graphAdapter = new JGraphXAdapter<String, MyEdge>(g);
layout = new mxOrganicLayout(graphAdapter);
layout.execute(graphAdapter.getDefaultParent());
mxGraphComponent component = new mxGraphComponent(graphAdapter);
component.setPreferredSize(new Dimension(dim.width - 50, dim.height - 200));
add(component);
我想按下一個按鈕
@Override
public void actionPerformed(ActionEvent e) {
String a="1";
String b="2";
g.addVertex(a);
g.addVertex(b);
g.addEdge(a,b);
}
public static class MyEdge extends DefaultWeightedEdge { //weight
@Override
public String toString() {
return String.valueOf(getWeight());
}
}
我怎樣才能刷新視圖後動態添加一個新的頂點?