图表不会显示

时间:2013-09-01 15:23:28

标签: java swing user-interface jframe jgraphx

我对gui和java很新,所以我只想尝试一些东西。我有这个类似于Hello World的小代码,即使没有错误,当我运行它时,我在控制台中得到的是:mxGraph版本“2.1.1.0” 我做错了什么想法?提前致谢

import javax.swing.JFrame;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;


public class Design extends JFrame {

    public Design() {

        super("Test");

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 320);
        f.setVisible(true);

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();


        graph.getModel().beginUpdate();
        try
        {
            Object v1 = graph.insertVertex(parent, null, "hi", 20, 20, 80,
                    30);
            Object v2 = graph.insertVertex(parent, null, "bye", 240, 150,
                    80, 30);
            graph.insertEdge(parent, null, "Edge", v1, v2);
        }
        finally
        {
            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        add(graphComponent);

        }

}

1 个答案:

答案 0 :(得分:2)

您可能正在看到类加载器的输出。添加main方法以显示JFrame本身

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            Design design = new Design();
            design.pack();
            design.setVisible(true);
        }
    });
}

你应该看到

enter image description here