JGraphX ​​setup

I use JGraphX ​​to display some data (simple discrete graphs), and I would like to know how to do the following with the JGraphX ​​library:

  • Make all faces stationary, but still allow the user to create an edge between two vertices
  • Make all vertices and edges immutable (they cannot edit what is displayed on them)
  • How to get the selected vertex or edge at any time?
  • Make all vertex boxes inaccessible to the user
  • How to change the color of each vertex window?

Thanks ExtremeCoder

+3
source share
1 answer

Here is an example:

mxGraph graph = new mxGraph()
{
  // Make all edges unmovable
  public boolean isCellMovable(Object cell)
  {
    return !getModel().isEdge(cell);
  }

  // Make all vertex boxes unresizable
  public boolean isCellResizable(Object cell)
  {
     return !getModel().isVertex(cell);
  }
};

// Make all vertices and edges uneditable
graph.setCellsEditable(false);

// Make all edges unbendable
graph.setCellsBendable(false);

// Get the selected vertex or edge
System.out.println(graph.getSelectionCell());

// To insert a vertex with a given color:
Object v1 = graph.insertVertex(parent, null, "Hello",
            20, 20, 80, 30, "fillColor=#FF0000;");

// To modify the color of a vertex:
graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, "#00FF00", new Object[]{v1});
+6
source

Source: https://habr.com/ru/post/1772107/


All Articles