简体   繁体   English

自定义JGraphX

[英]Customizing JGraphX

I have been using JGraphX to display some data (simple discrete graphs) and I would like to know how to do the following things with the JGraphX library: 我一直在使用JGraphX来显示一些数据(简单的离散图),我想知道如何用JGraphX库做以下事情:

  • Make all edges unmovable but still allow the user to create an edge between two vertices 使所有边不可移动但仍允许用户在两​​个顶点之间创建边
  • Make all vertices and edges uneditable (they cannot edit what is displayed on them) 使所有顶点和边不可编辑(它们无法编辑显示在它们上面的内容)
  • How do I get the selected vertex or edge at any given time? 如何在任何给定时间获得选定的顶点或边?
  • Make all vertex boxes unresizable to the user 使所有顶点框对用户不可调整
  • How do I modify the colour of each vertex's box? 如何修改每个顶点框的颜色?

Thanks, ExtremeCoder 谢谢,ExtremeCoder

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});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM