我发现如果我将组引入使用分层布局布局的简单图形中,则该组的位置不正确。
例如,这是一个简单的图表:
public class HierarchicalLayoutWithGrouping extends JFrame {
public HierarchicalLayoutWithGrouping() {
super("Hierarchical Layout With Grouping Test");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
Object transfer1 = graph.insertVertex(parent, null, "Transfer Data1.csv", 0, 0, 100, 40);
Object transfer2 = graph.insertVertex(parent, null, "Transfer Data2.csv", 0, 0, 100, 40);
Object load1 = graph.insertVertex(parent, null, "Load Data1.csv", 0, 0, 100, 40);
Object load2 = graph.insertVertex(parent, null, "Load Data1.csv", 0, 0, 100, 40);
graph.insertEdge(parent, null, null, transfer1, load1);
graph.insertEdge(parent, null, null, transfer2, load2);
Object calculate = graph.insertVertex(parent, null, "Calculate", 0, 0, 100, 40);
graph.insertEdge(parent, null, null, load1, calculate);
graph.insertEdge(parent, null, null, load2, calculate);
// Object loads = graph.insertVertex(parent, null, "Loads", 0, 0, 200, 400, "shape=swimlane;");
// graph.groupCells(loads, 5, new Object[] { load1, load2 });
mxHierarchicalLayout layout = new mxHierarchicalLayout(graph, SwingConstants.WEST);
layout.execute(parent);
} finally {
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
}
public static void main(String[] args) {
HierarchicalLayoutWithGrouping frame = new HierarchicalLayoutWithGrouping();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 450);
frame.setVisible(true);
}
}
产生这个美丽的图表:
但如果我取消注释以下几行:
Object loads = graph.insertVertex(parent, null, "Loads", 0, 0, 200, 400, "shape=swimlane;");
graph.groupCells(loads, 5, new Object[] { load1, load2 });
我明白了:
我已经尝试了各种选项,mxHierarchicalLayout
但还没有找到任何可行的方法。如何让它将组布局在正确的位置?
谢谢。