2014-03-31 30 views
0

我无法弄清楚如何为我的jrame放置滚动条,还是应该尝试放入jgraph内?我尝试了不同的东西,但它不是编译或不显示,或者它覆盖了图表?Java jframe 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); 
      */ 

回答

0

虽然我不喜欢创建和添加一个applet到JFrame的想法,正好有这么多的事情都可能出错...

看看How to use ScrollPanes

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

我会在哪里执行此操作?在主要还是jgraph?好吧,我已经在图形扩展小程序中工作了。谢谢。 – MAXGEN