Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Circular nodes in mxgraph

Raj Aditya KRaj Aditya K Member Posts: 1

I am new to mxGraphs. I want to create a graph with circular nodes but the code below creates a graph with rectangular nodes. Can someone please help?
` package p1;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import com.mxgraph.analysis.StructuralException;
import com.mxgraph.analysis.mxAnalysisGraph;
import com.mxgraph.analysis.mxGraphGenerator;
import com.mxgraph.analysis.mxTraversal;
import com.mxgraph.analysis.mxGraphProperties;
import com.mxgraph.analysis.mxGraphProperties.GraphType;
import com.mxgraph.analysis.mxGraphStructure;
import com.mxgraph.layout.mxCircleLayout;
import com.mxgraph.layout.mxCompactTreeLayout;
import com.mxgraph.layout.mxOrganicLayout;
import com.mxgraph.model.mxCell;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxGraph.mxICellVisitor;
import com.mxgraph.view.mxGraphView;
import com.mxgraph.costfunction.mxCostFunction;
import com.mxgraph.costfunction.mxDoubleValCostFunction;

        public class Graph extends JFrame
        {
                private static final long serialVersionUID = -2707712944901661771L;
                public Graph()
                {
                    super("Hello, World!");
                    mxGraph graph = new mxGraph();
                    Object parent = graph.getDefaultParent();
                    mxCircleLayout layout = new mxCircleLayout(graph,100);
                    layout.execute(parent);

                    graph.getModel().beginUpdate();
                    try
                    {
                        Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
                                    30);
                        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)
                {
                    Graph frame = new Graph();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setSize(400, 320);
                    frame.setVisible(true);
                }
        }`
Sign In or Register to comment.