javaswingmxgraphjgraph

Is there any way to change the vertex or the edges style from mxgraph?


I made a graph using java and i want to customize the style of it. Is there any easy way? By adding style to them? Here is a part of the code that i used: Its getting some data from a json file that are filled to some Hashmaps.

public mxGraphComponent createGlobalOverview(String Filename) {
            mxGraph graph = new mxGraph();
            Object parent = graph.getDefaultParent();

            graph.getModel().beginUpdate();
            try {
                  Object vRoot = graph.insertVertex(parent, null, Filename, 0, 0, 100, 50);
                  int fmsCounter = 0;

                  for (Object i : blueprint.keySet()) {
                      getDependencies(i.toString());
                      if (blueprint.get(i).equals("FMS")) {
                          if (dependsList.get(fmsCounter).equals("null")) {
                              Object rootFMS = graph.insertVertex(parent, null, getTitle(i.toString()), 0, 0, 200, 50);
                              graph.insertEdge(parent, null, "rootFMS", vRoot, rootFMS);
                              System.out.println(blueprint.size());
                              createGraph(graph, parent, rootFMS, i, blueprint.size());
                            }
                        }
                    }
                    graph.setCellsEditable(false);
                    graph.setCellsMovable(false);
                    graph.setCellsResizable(false);
                    graph.setCellsSelectable(false);
                    graph.setEnabled(false);
                    mxIGraphLayout layout = new mxHierarchicalLayout(graph);
                    layout.execute(parent);

              } finally {
                    graph.getModel().endUpdate();
                }
                graph.getView().setScale(0.9);
                mxGraphComponent graphComponent = new mxGraphComponent(graph);
                graphComponent.setConnectable(false);
                return graphComponent;
 }

Solution

  • You could use the mxStyleChange() API Documentation

    mxStyleChange​(mxGraphModel graph, java.lang.Object cell, java.lang.String style)   
    

    To know more about the layouts, you shoud take a look here, this will help you defining the style. The shapes might be useful as well:

    The API documentation is extensive, you should always take a look there. Hope this helps you