[英]How to put non-editable elements in JPGraph
Im working on a code that shows a full graph and uses Dijkstra's algoritm to show the shortest path. 我正在处理显示完整图形并使用Dijkstra算法的代码以显示最短路径的代码。 But the problem is: it doesnt simply visaluizate things, they're all editable and interactible.
但是问题是:它不只是将事物虚化,它们都是可编辑和可交互的。
I just need to visualize "the graph" and no to: move, edit, add, or make any interaqction with nodes and/or edges. 我只需要可视化“图形”,而无需:移动,编辑,添加或与节点和/或边进行任何交互。
In this simple Jframe is where I've been trying to eliminate those interactions. 在这个简单的Jframe中,我一直在尝试消除这些交互。 But i have been failing:
但是我一直失败:
public class Actions extends JFrame {
private mxGraph graph;
private mxGraphComponent graphComponent;
public Actions() {
super("JGraph - labyrinth");
initGUI();
}
private void initGUI() {
setSize(800,600);
setLocationRelativeTo(null);
graph = new mxGraph();
graphComponent = new mxGraphComponent(graph);
graphComponent.setPreferredSize(new Dimension(400, 400));
getContentPane().add(graphComponent);
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
graph.insertVertex(parent, null, "TEST", 30, 80, 100, 50);
graph.getModel().endUpdate();
}
} }
So this program generates a node with the "TEST" String as name. 因此,此程序将生成一个以“ TEST”字符串作为名称的节点。 The problem is: i can interact with this single node, i can move it everywhere, i can make many new edges as i want from the "TEST" node.
问题是:我可以与该单个节点进行交互,可以将其移动到任何地方,也可以根据需要从“ TEST”节点中获得许多新的优势。 And i dont want that, i just want to visaluizate my graph, no to interact with it.
而且我不希望那样,我只是想使我的图表虚化,而不是与其交互。
EDIT : I managed to make the node unmovable, but I can still create / interact with its edges. 编辑 :我设法使节点不可移动,但我仍然可以创建/与其边缘进行交互。 This is the code i added:
这是我添加的代码:
graph.setCellsLocked(true);
graph.setVertexLabelsMovable(false);
graph.setEdgeLabelsMovable(false);
Try extending mxGraph and overriding the isCellSelectable method. 尝试扩展mxGraph并覆盖isCellSelectable方法。
public class Graph extends mxGraph {
@Override
public boolean isCellSelectable(Object cell) {
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.