2014年1月2日星期四

Seek expert coaching " to increase my chat interface : the user's focus to the input text " track display " message board " function

. Master, hello :
I'm doing an IM tool , as a novice Java soon , I hope to be able to my "JTextArea object" , add my " based on user input " a " message board trace output "effect :
both to the user receives a " message board beyond the boundaries of the " chat message "" to " the user's message board has been filled data on top" function realization .
said to need help to :
(JTextArea) recvArea.setCaretPosition (recvArea.getText (). length ()),
Move the cursor to the end, to achieve the scroll bar automatically scroll .
function.
experts hope to be able to share:
above functions to achieve the "core code " , what ....
Thank you, master 's help ! !
------ Solution ---------------------------------------- ----
JTextComponent this is a function of it. Is simply to set the caret position

public void setCaretPosition (int position)
Sets the position of the text insertion caret for the TextComponent. Note that the caret tracks change, so this may move if the underlying text of the component is changed. If the document is null, does nothing. The position must be between 0 and the length of the component's text or else an exception is thrown.
Parameters:
position - the position
Throws:
IllegalArgumentException - if the value supplied for position is less than zero or greater than the component's text length

specific http://docs. oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html # setCaretPosition (int)

------ Solution ------------------------------------ --------
http:// www.cnblogs.com/lionden/archive/2012/10/17/swing_textarea.html
------ For reference only --------------- ------------------------
I came to see a response.
------ For reference only -------------------------------------- -
thank two teacher's guide ! !
Thank you join a small wire Cock ! !
hundred full offer ! !

没有评论:

发表评论