帮助 - 搜索 - 坛友 - 日历
完整版本: Java again! JTextArea滚动条
大家谈论坛 > 大家坛 > 留学问题求助,解答
Jie.jz
设计GUI。
创建一个Plain Text Area,能够将输入的内容打印在Text Area中,当内容超过这个文本栏的长度以后,怎样让滚动条自动往下翻到最新的输入内容末尾呢? em39.gif
Jie.jz
自己顶一下。没有人知道么? em87.gif
Roronoa
i dont know if i get what u mean there

but here is the stupid method

get the length of the string in the text field e.g. M
get the size of the text area e.g. N


display the first N chars of string M for the first x second

define a loop
if u want it to move row by row
then display the next N chars from M starting (M- row width)
keep doing this until the M- y*rowWidth <= N
start from the begining
Roronoa
u might need to create a seperate thread to do that though....not too sure
bluexmass
Roronoa厉害,顶一个
Jie.jz
QUOTE (Roronoa @ 2006-01-16, 15:16)
i dont know if i get what u mean there

but here is the stupid method

get the length of the string in the text field e.g. M
get the size of the text area e.g. N


display the first N chars of string M for the first x second

define a loop
if u want it to move row by row
then display the next N chars from M starting (M- row width)
keep doing this until the M- y*rowWidth <= N
start from the begining

抱歉了还是说的不够清楚。em07.gif
说清楚一下:
我设计的GUI中有一个JTextArea;
程序的Output会打印在这个JTextArea中(apend命令);
这些输出的内容会自动换行,所以不会有左右的滚动条出现;
当输出的内容超过JTextArea的固定高度的时候,上下滚动条出现;
希望实现的功能就是:当新内容输入超过高度时,上下滚动条能够自动滑到底部的新输入处(i.e.文档的末尾),但是并不擦除之前显示的内容。

谢谢Roronoa的方法,先拜一个了 em07.gif
Roronoa
textareaname.scrollTop = textareaname.scrollHeight;


something like this?
这是我们主要内容的一个简化版本. 若您想查看包含更多信息和格式化的完整版本请您访问这里.
Invision Power Board © 2001-2008 Invision Power Services, Inc.
Translated By IBForce