JTextArea tp=new JTextArea();
new JScrollPane(tp);

解决方案 »

  1.   

    没人回答吗,如果我加一个jScrollPane控件的话,拖动窗提改变窗体大小的话,jScrollPane里面的东西总是不能很好的跟着变化
      

  2.   

    如果用AWT里的TextArea控件很好用,可惜我的菜单都是Swing的,这样就跑到TextArea下面去了,用JTextArea又这么难用,有高人指路吗?
      

  3.   

    //try this, you will get a basic idea about this topic
    //good luckimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class JTextFrameClass extends JFrame {
      private JPanel contentPane;
      private BorderLayout borderLayout1 = new BorderLayout();
      private JScrollPane jScrollPane1 = new JScrollPane();
      private JTextArea jTextArea1 = new JTextArea();  //Construct the frame
      public JTextFrameClass() {
        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");
        contentPane.setToolTipText("");
        jTextArea1.setBackground(Color.pink);
        jTextArea1.setText("jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
                           "jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
                           "jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
                           "jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!");
        jTextArea1.setLineWrap(true);
        jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        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);
        }
      }  public static void main (String args[])
      {
        JTextFrameClass test = new JTextFrameClass();
        test.setSize(200,150) ;
        test.show();
      }
    }