public   class   ScrollpanTest{
JInternalFrame   frame;
JFrame mainFrame ;
    JPanel   pane;
    JScrollPane   s;
    JTextArea   t;
    public   ScrollpanTest()   {
        t   =   new   JTextArea(100,200);
        mainFrame=new JFrame("mainFrame");
        frame   =   new   JInternalFrame( "JScrollPane ");
        
        
        JDesktopPane desktop=new JDesktopPane();
        desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
        desktop.add(frame,JLayeredPane.DEFAULT_LAYER);
        
        pane   =   new   JPanel();
        s   =   new   JScrollPane(pane);
        JTabbedPane tabedPane=new JTabbedPane();
        tabedPane.add("za",s);
        
        frame.add(tabedPane);
        pane.add(t);
        //frame.setSize(300,   200);
       
        mainFrame.getContentPane().add(desktop, BorderLayout.CENTER);
        //mainFrame.add(frame);
        mainFrame.setSize(600,800);
        mainFrame.setVisible(true);
        frame.setVisible(true);
        
    }    public   static   void   main(String[]   args)   {
     ScrollpanTest   test   =   new   ScrollpanTest();
    } 
}

解决方案 »

  1.   


     JScrollPane s;把什么加到里面去了?
      

  2.   

    // 將文本區域的滾動條設置成垂直滾動條一直顯示,水平滾動條一直不顯示
    jScrollPane2 = new JScrollPane(jTextArea1,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
    );
      

  3.   

    你可以参照一下代码:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JFrame{
     JScrollPane pane;
     JButton button;
     public Test(){
      super();
      pane=new JScrollPane(new JTextArea());
      button=new JButton("点击");
      add(pane,BorderLayout.CENTER);
      add(button,BorderLayout.SOUTH);
      button.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
         JScrollBar bar=pane.getVerticalScrollBar();
         bar.setValue(bar.getMaximum());
        }
       });
     }
     public static void main (String[] args) {
      JFrame frame=new Test();
      frame.setVisible(true);
      frame.setBounds(100,100,300,300);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
    }