Question

Je n'ai pas pu trouver de réponse dans le manuel, ou sur ainsi. Je veux faire un graphique avec JGraphx qui affiche certains vérifications et bords, mais je ne veux pas que l'utilisateur puisse déplacer quoi que ce soit, ni pour que ces boîtes de modification vertes apparaissent sur les vortex ou les bords. C'est juste pour l'affichage uniquement.

J'ai essayé cette modification de l'exemple "Hello World" en vain. Aucune suggestion?

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

}
Était-ce utile?

La solution

Vous pouvez désactiver l'ensemble du composant graphique mxGraphComponent:

graphComponent.setEnabled(false);

Autres conseils

Vous pourriez remplacer isCellSelectable Pour éviter la sélection des cellules

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);
      }
};
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top