I want to create simple graph inside a JScrollPane present in my GUI. I was trying to do so by using the "Hello world" example distributed with JGraphX, the resutlt is as shown below:
public class GraphTest{
public GraphTest(FrameWithScrollPane frame)
{
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
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);
frame.setNewPane(new JScrollPane(graphComponent));
}
public static void main(String[] args)
{
FrameWithScrollPane frame = new FrameWithScrollPane();
frame.setVisible(true);
GraphTest test = new GraphTest(frame);
}
}
Here I was trying to replace already existing JScrollPane with a new one, but I can't get this to work. The only way to insert a graph in a JScrollPane seems to be having a clean JFrame, and then creating a whole new JScrollPane, with graphComponent as a constructor's argument... which is not what I need, already working with a complex GUI modeled with Netbeans GUI Builder. Adding graphComponent to existing JScrollPane also doesn't work. Does anyone have any ideas?