1.放在ScrollPanel中的组件一般不需要设置大小.
2.
    jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

解决方案 »

  1.   

    我试过还是不行,效果是全屏时jScrollPane外面增加了垂直和水平的滚动条,未全屏时还是没滚动条出现。
      

  2.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Frame1 extends JFrame
    {
        JPanel contentPane;
        BorderLayout borderLayout1 = new BorderLayout();
        JScrollPane jScrollPane1 = new JScrollPane();
        JTextArea jTextArea1 = new JTextArea();    //Construct the frame
        public Frame1()
        {
            enableEvents(AWTEvent.WINDOW_EVENT_MASK);
            try
            {
                jbInit();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        //Component initialization
        private void jbInit() throws Exception
        {
            contentPane = (JPanel) this.getContentPane();
            contentPane.setLayout(borderLayout1);
            this.setSize(new Dimension(400, 300));
            this.setTitle("Frame Title");
            jTextArea1.setText("jTextArea1");
            contentPane.add(jScrollPane1, BorderLayout.CENTER);
            jScrollPane1.getViewport().add(jTextArea1, null);
        }
        //Overridden so we can exit when window is closed
        protected void processWindowEvent(WindowEvent e)
        {
            super.processWindowEvent(e);
            if (e.getID() == WindowEvent.WINDOW_CLOSING)
            {
                System.exit(0);
            }
        }
    }
    ///////////////////////////////////
    import javax.swing.UIManager;
    import java.awt.*;public class Application1
    {
        boolean packFrame = false;    //Construct the application
        public Application1()
        {
            Frame1 frame = new Frame1();
            //Validate frames that have preset sizes
            //Pack frames that have useful preferred size info, e.g. from their layout
            if (packFrame)
            {
                frame.pack();
            }
            else
            {
                frame.validate();
            }
            //Center the window
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = frame.getSize();
            if (frameSize.height > screenSize.height)
            {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width)
            {
                frameSize.width = screenSize.width;
            }
            frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
            frame.setVisible(true);
        }
        //Main method
        public static void main(String[] args)
        {
            try
            {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            new Application1();
        }
    }
      

  3.   

    有关滚动条和文本的就这些 
    JEditTextArea jEditTextArea = new JEditTextArea();
            jEditTextArea.setText("");
       jEditTextArea.getDocument().addDocumentListener(new
            EditorPanel_jEditTextArea_DocumentListener(this));
      
      JScrollPane jScrollPane2 = new JScrollPane();
        jTabbedPane1.add(jScrollPane2, "jsp source");
        jScrollPane2.getViewport().add(jEditTextArea, null);