Topic: 如何实现JScrollPane自动滚动??

  Print this page

1.如何实现JScrollPane自动滚动?? Copy to clipboard
Posted by: lxf9501
Posted on: 2003-07-16 16:05

JScrollPane上有一个JTextArea,主要是用来显示log,
并且希望看到的总是当前的log。
但是用JTextArea.append("...")时,
JScrollPane不会滚动,导致看到的总是最早的log,
需要看最新的,要手动下滚!

哪位能解决?

期待!

2.Re:如何实现JScrollPane自动滚动?? [Re: lxf9501] Copy to clipboard
Posted by: szmustang
Posted on: 2003-07-17 13:42

你插入一条数据后就应该用SetCaretPosition把光标移动到当前位置

3.Re:如何实现JScrollPane自动滚动?? [Re: lxf9501] Copy to clipboard
Posted by: roshin
Posted on: 2003-07-17 16:31

试一下着个:
getVerticalScrollBar().setValue()

4.Re:如何实现JScrollPane自动滚动?? [Re: lxf9501] Copy to clipboard
Posted by: Julian13
Posted on: 2003-07-17 23:18

i've been using a tricky way doing auto-scroll for JTextPane. hope this work for you too.

the idea is to enforce the viewport scroll to the last line of the by selecting the last character of the text. here is the code:

JTextPane pane = new JTextPane();
... // add some text to the JTextPane
...
Document doc = pane.getDocument();
pane.select(doc.getLength(), doc.getLength()); // this should enforce the viewport move to where the line being selected.
...


i've been using it to display process log. so, you can try about it.
have fun.

5.Re:如何实现JScrollPane自动滚动?? [Re: szmustang] Copy to clipboard
Posted by: floater
Posted on: 2003-07-18 00:59

szmustang wrote:
你插入一条数据后就应该用SetCaretPosition把光标移动到当前位置

I think this is the current way to do it.

6.Re:如何实现JScrollPane自动滚动?? [Re: Julian13] Copy to clipboard
Posted by: littledeer1974
Posted on: 2005-09-14 15:55


yourTextArea.setCaretPosition(yourTextArea
.getDocument().getLength());


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923