我一直在使用JGraphX来显示一些数据(简单的离散图),我想知道如何使用JGraphX库完成以下操作:
- 使所有边缘不可移动,但仍允许用户在两个顶点之间创建边缘
- 使所有顶点和边缘不可编辑(不能编辑它们上面显示的内容)
- 如何在任何给定时间获取所选顶点或边缘?
- 使所有顶点框对用户不可调整大小
- 如何修改每个顶点框的颜色?
谢谢,ExtremeCoder
这里有一个例子:
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});