swing中JScrollPane 能否直接加到JFrame上?

解决方案 »

  1.   

    JScrollPane sp new JScrollPane();
    JFrame jf new JFrame();
    jf.getContentPane().setLayout(new BorderLayout());
    jf.getContentPane().add(sp, "Center");
      

  2.   

    LZ是想直接调用 JFrame.add(new ScrollPane()) 吧1、在JDK1.5之前,像上面那么做是不可以的
    JFrame.getContentPane().add(sp); //默认的BorderLayut2、在包括1.5之后的版本,就可以直接调用JFrame.add(new ScrollPane())了
      

  3.   


    JTextArea jta=new JTextArea();
    JScrollPane jsp=new JScrollPane(jta);
    this.setLayout(new BorderLayout());
    this.add(jsp,BorderLayout.CENTER);
      

  4.   

    JScrollPane sp = new JScrollPane(); 
    JFrame frame= new JFrame(); 
    frame.getContentPane().add(sp);    //这里可是关键噢,就可以证明JScrollPane可以添加到JFrame中了