在JTextArea里面有setScrollOffset,或者通过setSelectionStart,setSelectionEnd来实现。我没做过(vc里面这种方法是没有问题的),你可以试一下

解决方案 »

  1.   

    这里有一个关于scoll的例子
    http://javaboutique.internet.com/Scrollup/
      

  2.   

    this.jTextArea1.requestFocus();
        this.jTextArea1.setSelectionStart(this.jTextArea1.getText().length());
        this.jTextArea1.setSelectionEnd(this.jTextArea1.getText().length());
      

  3.   

    好象上边的方法不行
    是不是要将JTextArea1.SetEnable(True)有关
    还有是不是和ContentPane的Layout的设置有关我设置的XYLayout
    我的部分代码:
     contentPane.add(jScrollPane1, null);
     jScrollPane1.setAutoscrolls(true);
     jScrollPane1.getViewport().add(jTextArea2,null);
     jTextArea1.setLineWrap(true);
     this.jTextArea1.requestFocus();
     this.jTextArea1.setSelectionStart(this.jTextArea1.getText().length());
    this.jTextArea1.setSelectionEnd(this.jTextArea1.getText().length());
      

  4.   

    上面的方法是可行的,这是个例子,你看看
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Frame1 extends JFrame {
      private JPanel contentPane;
      private JLabel jLabel1 = new JLabel();
      private JButton jb=new JButton("click");
      private JPanel jp=new JPanel(new FlowLayout());
      private JScrollPane jscr=new JScrollPane();
      private JTextArea jta=new JTextArea();
      public Frame1() {
        super("myFrame");
        this.setSize(400,300);
        this.setResizable(false);
        this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(new BorderLayout());
        contentPane.add("South",jp);
        contentPane.add("Center",jscr);
        jscr.getViewport().add(jta);
        jta.setText("start\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend");
        jp.add(jb);
        jb.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            click(e);
          }
        });
        this.setSize(new Dimension(400, 300));
        this.setTitle("Frame Title");
        for(int i=1;i<=9;i++) {
      for(int j=1;j<=i;j++) {
        if(j!=1)
          System.out.print(",");
        System.out.print(j+"*"+i+"="+i*j);
      }
      System.out.println("");
        }
        this.setVisible(true);
      }  public void click(ActionEvent e) {
        this.jta.requestFocus();
        this.jta.setSelectionStart(this.jta.getText().length());
        this.jta.setSelectionEnd(this.jta.getText().length());
      }  public static void main(String args[]) {
        new Frame1();
      }
    }