Java 组在JGraphX中打断层次结构布局
我发现,如果我在一个简单的图中引入组,并用层次结构布局,则组的位置不正确 例如,下面是一个简单的图表:Java 组在JGraphX中打断层次结构布局,java,swing,jgraphx,Java,Swing,Jgraphx,我发现,如果我在一个简单的图中引入组,并用层次结构布局,则组的位置不正确 例如,下面是一个简单的图表: public class HierarchicalLayoutWithGrouping extends JFrame { public HierarchicalLayoutWithGrouping() { super("Hierarchical Layout With Grouping Test"); mxGraph graph = new mxGr
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 });
我明白了:
我在MXCallayout
上尝试了各种选项,但还没有找到任何有效的方法。
我如何让它在正确的位置上布局组
谢谢。我发现,分组框得到了另一个层次结构,作为未分组的节点。这就是为什么每个分组框都移动到新行的原因。我认为除了编写自己的布局算法,或者在布局执行期间重写生成层次属性的方法之外,没有其他可能性