Jgraph in JavaFx

*爱你&永不变心* 提交于 2019-12-11 07:46:52

问题


Is it possible to use jgraphx with JavaFx 2.0?

I have tried using the below code, but i could not add the graph component to the JavaFx component.

        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);
        TitledPane tPane = new TitledPane();
        tPane.setAnimated(false);
        tPane.setExpanded(false);
        tPane.setMaxWidth(1040);
        tPane.setText("Load Module " + i);
        tPane.setAnimated(true);
        tPane.setContent(graphComponent); // Error here. setContent() does not accept graph

How can i use/add jgraph to the JavaFX component? Any ideas ?


回答1:


jgraph is a Swing-based library. Currently Swing programs can embed JavaFX components, but JavaFX programs cannot embed Swing components. Java 8 will include an ability for JavaFX programs to embed Swing components. This will accelerate Java FX's adoption for sure. But for JavaFX 2.x, it's either one or the other.



来源:https://stackoverflow.com/questions/18372330/jgraph-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!