我正在使用 JGraphX 库并尝试使用mxFastOrganicLayout执行自动布局:
import javax.swing.JFrame;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
public class FastOrganic extends JFrame {
public static void main(String[] args) {
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
30);
Object v2 = graph.insertVertex(parent, null, "World!", 240, 150,
80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
} finally {
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
FastOrganic frame = new FastOrganic();
frame.add(graphComponent);
frame.pack();
frame.setVisible(true);
}
}
我想了解如何应用快速有机布局,文档将其定义为mxFastOrganicLayout
. 问题是我不能把它变成这样的组件:
mxGraphComponent graphComponent = new mxGraphComponent(graph);
asmxGraphComponent
不接受mxFastOrganicLayout
作为构造函数,而是mxFastOrganicLayout
接受mxGraph
,这似乎是正确的一步?我将不胜感激任何帮助,问候。