1

I'm using JGraphT to create a graph and I want to be able to visualise and manipulate it. There are some examples that show how to visualise the graph, but it seems that it involves quite a lot of manual code to layout the vertices, etc. I was wondering if there was any graph layout algorithm that could automate this process already in JGraph with a small example. Mostly the graphs I'm drawing are Directed Acyclic Graphs. I have already drawn the graphs by exporting them to .dot format and display it using dot, but I need a little interaction now.

1 Answer 1

3

Since JGraph seems to now be mxGraph, but JGraphT embed JGraph 5.13, it's not that easy but I've found this doc and the following piece of code is working:

    // this a a JGraphT graph
    ListenableDirectedGraph<TableColumn, DefaultEdge> dependencyGraph = getDependencyGraph();

    JGraphModelAdapter adapter = new JGraphModelAdapter(dependencyGraph);

    JGraph jgraph = new JGraph(adapter);


    JGraphLayout layout = new JGraphHierarchicalLayout(); // or whatever layouting algorithm
    JGraphFacade facade = new JGraphFacade(jgraph);
    layout.run(facade);
    Map nested = facade.createNestedMap(false, false);
    jgraph.getGraphLayoutCache().edit(nested);

    JScrollPane sp = new JScrollPane(jgraph);
    this.add(sp);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.