2

GUI に存在する JScrollPane 内に単純なグラフを作成したいと考えています。JGraphXで配布されている「Hello world」の例を使用してそうしようとしましたが、結果は次のようになります。

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

ここで、既存の JScrollPane を新しいものに置き換えようとしましたが、これを機能させることができません。JScrollPane にグラフを挿入する唯一の方法は、きれいな JFrame を用意してから、graphComponent をコンストラクターの引数として使用してまったく新しい JScrollPane を作成することのようです...これは私が必要としているものではなく、モデル化された複雑な GUI で既に作業していますNetbeans GUI ビルダー。既存の JScrollPane に graphComponent を追加しても機能しません。誰にもアイデアはありますか?

4

0 に答える 0