Java jframe jgraph滚动平面

时间:2014-03-31 21:09:22

标签: java scroll jframe jgrapht jgraph

我无法弄清楚如何为我的jrame设置滚动条,还是应该尝试放入jgraph?我尝试过不同的东西,但要么不编译,要么不显示或覆盖图表?

main java

   final GraphMain applet=new GraphMain(file);
            applet.init();
            JFrame f=new JFrame("Title goes here");
            f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            f.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e){
                    applet.stop();
                    applet.destroy();
                    System.exit(0);
                }
            });
            f.setLayout(new BorderLayout());
            f.add(applet, BorderLayout.CENTER);
            f.setSize(DEFAULT_SIZE1);
            applet.start();
            f.setVisible(true);

jgraph扩展了JApplet

   // create a JGraphT graph
           UndirectedGraph<String, DefaultEdge> g = 
                new ListenableUndirectedGraph<String, DefaultEdge>( DefaultEdge.class );

            // create a visualization using JGraph, via an adapter
            m_jgAdapter = new JGraphModelAdapter<String, DefaultEdge>( g );

            JGraph jgraph = new JGraph( m_jgAdapter );

            adjustDisplaySettings( jgraph );
            getContentPane(  ).add( jgraph );
            resize( DEFAULT_SIZE );

           /* scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 50, 0, 0, 100);
            add(scrollbar);*/
           /* scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 50, 0, 0, 100);
            add(scrollbar);
            scrollbar.addAdjustmentListener(this);
            */

1 个答案:

答案 0 :(得分:0)

虽然我不喜欢在JFrame中创建和添加applet的想法,但是有很多事情可能会出错......

查看How to use ScrollPanes

getContentPane().add( new JScrollPane(jgrap));