本一点的办法,你在那个改变JEditorPane内容的线程中模拟按钮的点击

解决方案 »

  1.   

    After you setText(), add the following codes://go to end
    editorPane.selectAll();
    int length=editroPane.getSelectedText().length();
    editorPane.setSelectionStart(length);
    editorPane.setSelectionEnd(length); //must have this statement.//if go to home:
    editorPane.setSelectionStart(0);
    editorPane.setSelectionEnd(0); //must have
      

  2.   

    两种方法可以解决:
    1、控制JScrollBar,在setText(String)后计算JScrollBar的最大位置
    JScrollPane sPane = new JScrollPane(textArea);
    JScrollBar sBar = sPane.getVerticalScrollBar();
    sBar.setValue(int value);//value为具体的位置sBar.getMaximum()//得到最大
    sBar.getMinimum()//得到最小sBar.setValue(int value);要写在setVisible(true);后面
    2、将光标设置到输入字符串的末尾
    textPane.setCaretPosition(int position);
    //editroPane.getSelectedText().length();可取得editroPane中字符串的总数
    <------ 树欲静而风不止 ------>
      

  3.   

    这几种方法都是在事后让它滚下来
    可是为什么窗体事件里,例如:
    JTextField里面keyPress事件中
    if (evt.getKeyCode()==KeyEvent.VK_ENTER ){
                //content是StringBuffer
                content.append(JTextField.getText());
                JEditorPane.setText(content.toString());
            }这种情况下内容不会跳到顶部,而且自动向下滚。但是在后台线程调用JEditorPane.setText(content.toString());,内容会跳到顶部。何解?如何解决?
      

  4.   

    I did not find the problem you described. 
    post your code.
      

  5.   

    代码太长了其实就是一个聊天室客户端有一个线程接收数据
    while (true){
                        theLine = networkIn.readLine();
                        if(theLine==null)break;
                        content.append(theLine);//content是一个StringBuffer
                        jEditorPane.setText(content.toString());
                    }
    这样刷新内容后,pane里面显示在整个内容的最上面如果是在JTextField里面keyPress事件中
    if (evt.getKeyCode()==KeyEvent.VK_ENTER ){
                //content是StringBuffer
                content.append(JTextField.getText());
                JEditorPane.setText(content.toString());
            }这种情况下内容不会跳到顶部,而且自动向下滚。
      

  6.   

    有一个骗人的办法:滚动条在最顶端的时候看不到,当把它移到了最下面,这时候再让可见。
    在JFrame中的BorderLayout.CENTER中同时加两个相同的JEditorPane,先将最上面的隐藏,给隐藏的JEditorPane中setText(String str)和设置好了滚动条位置后再把它显示出来,这样看着就好象直接到了最底部。
    呵呵~~~~这样做很麻烦,而且也没什么意思,建议你写个方法让滚动条以加速度自动滚下来,这样看着效果也会不错的。<------ 树欲静而风不止 ------>