Java JGraphX-希望整个图形不可编辑

Java JGraphX-希望整个图形不可编辑,java,swing,jgraphx,Java,Swing,Jgraphx,我在手册中找不到答案,或者诸如此类。我想用JGraphX制作一个图形,显示一些真实和边缘,但我不希望用户能够移动任何东西,也不希望那些绿色的编辑框出现在漩涡或边缘上。这只是为了展示而已 我尝试了对“Hello World”示例的这种修改,但没有成功。有什么建议吗 package com.mxgraph.examples.swing; import java.util.Hashtable; import javax.swing.JFrame; import com.mxgraph.swing

我在手册中找不到答案,或者诸如此类。我想用JGraphX制作一个图形,显示一些真实和边缘,但我不希望用户能够移动任何东西,也不希望那些绿色的编辑框出现在漩涡或边缘上。这只是为了展示而已

我尝试了对“Hello World”示例的这种修改,但没有成功。有什么建议吗

package com.mxgraph.examples.swing;

import java.util.Hashtable;

import javax.swing.JFrame;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxStylesheet;

public class HelloWorld extends JFrame
{

/**
 * 
 */
private static final long serialVersionUID = -2707712944901661771L;

public HelloWorld()
{
    super("Hello, World!");

    mxGraph graph = new mxGraph();
    Object parent = graph.getDefaultParent();

            //my addition of a stylesheet, I used it on the first node to see if it mad
            //a difference, it didn't regarding dragability//////////////////////////////
    mxStylesheet stylesheet = graph.getStylesheet();
    Hashtable<String, Object> style = new Hashtable<String, Object>();
    style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
    style.put(mxConstants.STYLE_OPACITY, 50);
    style.put(mxConstants.STYLE_FONTCOLOR, "#774400");
    style.put(mxConstants.STYLE_EDITABLE, false);
    stylesheet.putCellStyle("ROUNDED", style);

            //tried this too///////////////////////////////////////////////
    graph.setCellsEditable(false); 

    graph.getModel().beginUpdate();
    try
    {
        Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
                30, "ROUNDED");
        Object v2 = graph.insertVertex(parent, null, "World!", 240, 150,
                80, 30);
        graph.insertEdge(parent, null, "Edge", v1, v2);
    }
    finally
    {
        graph.getModel().endUpdate();
    }

    mxGraphComponent graphComponent = new mxGraphComponent(graph);
    getContentPane().add(graphComponent);
}

public static void main(String[] args)
{
    HelloWorld frame = new HelloWorld();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 320);
    frame.setVisible(true);
}

}
package com.mxgraph.examples.swing;
导入java.util.Hashtable;
导入javax.swing.JFrame;
导入com.mxgraph.swing.mxGraphComponent;
导入com.mxgraph.util.mxConstants;
导入com.mxgraph.view.mxgraph;
导入com.mxgraph.view.mx样式表;
公共类HelloWorld扩展了JFrame
{
/**
* 
*/
私有静态最终长SerialVersionId=-2707712944901661771L;
公共HelloWorld()
{
超级(“你好,世界!”);
mxGraph=新的mxGraph();
对象父对象=graph.getDefaultParent();
//我添加了一个样式表,我在第一个节点上使用它来查看它是否疯狂
//不同的是,它不考虑拖航性//////////////////////////////
mxStylesheet stylesheet=graph.getStylesheet();
Hashtable style=新的Hashtable();
style.put(mxConstants.style\u形状,mxConstants.SHAPE\u椭圆);
style.put(mxConstants.style_不透明度,50);
style.put(mxConstants.style_FONTCOLOR,#774400“);
style.put(mxConstants.style\u可编辑,false);
样式表。putCellStyle(“圆形”,样式);
//我也试过这个///////////////////////////////////////////////
graph.setCellsEditable(false);
graph.getModel().beginUpdate();
尝试
{
Object v1=graph.insertVertex(父对象,null,“Hello”,20,20,80,
30,“四舍五入”);
Object v2=graph.insertVertex(父对象,null,“World!”,240,150,
80, 30);
插入边(父,空,“边”,v1,v2);
}
最后
{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent=新mxGraphComponent(图形);
getContentPane().add(graphComponent);
}
公共静态void main(字符串[]args)
{
HelloWorld框架=新HelloWorld();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
框架。设置尺寸(400320);
frame.setVisible(true);
}
}

您可以覆盖
isCellSelectable
以防止单元格选择

mxGraph graph = new mxGraph() {

    @Override
      public boolean isCellSelectable(Object cell) {
         if (cell != null) {
            if (cell instanceof mxCell) {
               mxCell myCell = (mxCell) cell;
               if (myCell.isEdge())
                  return false;
            }
         }
         return super.isCellSelectable(cell);
      }
};

您可以禁用整个图形组件
mxGraphComponent

graphComponent.setEnabled(false);