0

我不知道如何为我的 jrame 放置滚动条,还是应该尝试将其放在 jgraph 中?我尝试了不同的东西,但它要么不编译,要么不显示,或者它覆盖了图表?

主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);
            */
4

1 回答 1

0

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

看看如何使用 ScrollPanes

getContentPane().add( new JScrollPane(jgrap));
于 2014-03-31T21:40:22.943 回答