JGraphx : How to avoid adding edges over each other?

走远了吗. 提交于 2019-12-12 10:24:01

问题


I'm working on an application using jGraphx and I want to know how to avoid creating edges over each other.

When I add 2 edges between 2 vetexes, the 2 edges are above eatch other..

Thanks in advance.

EDIT : That's what I get, those are 2 edges with the labels : "dist = 1" and "dist = 4" above each other.


回答1:


It can be done easily:

    new mxCircleLayout(graph).execute(graph.getDefaultParent());
    new mxParallelEdgeLayout(graph).execute(graph.getDefaultParent());



回答2:


Without seeing any of your source code it's hard to offer specific details, but in general, what you need to do is get the graph's stylesheet, and then modify the edge related parameters. An example is:

    mxGraph mxgraph = new mxGraph();
    Object parent = mxgraph.getDefaultParent();
    mxgraph.getModel().beginUpdate();
    mxStylesheet stylesheet = mxgraph.getStylesheet();
    Hashtable<String, Object> style = new Hashtable<>();
    stylesheet.putCellStyle("ROUNDED", style);

    Map<String, Object> vertexStyle = stylesheet.getDefaultVertexStyle();
    vertexStyle.put(mxConstants.STYLE_FILLCOLOR, "#FFFFFF");
    vertexStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000");
    vertexStyle.put(mxConstants.STYLE_AUTOSIZE, 1);
    vertexStyle.put(mxConstants.STYLE_SPACING, "10");
    vertexStyle.put(mxConstants.STYLE_ORTHOGONAL, "true");
    vertexStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);

    Map<String, Object> edgeStyle = stylesheet.getDefaultEdgeStyle();
    edgeStyle.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL);
    edgeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CURVE);
    edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);

    ...set up your edges and vertices here, where the last parameter is "ROUNDED" (the name of the stylesheet)

    mxgraph.getModel().endUpdate();


来源:https://stackoverflow.com/questions/28771698/jgraphx-how-to-avoid-adding-edges-over-each-other

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!