tags:

views:

54

answers:

3

Hello, I have JTextPane on my window and i have JTextField. When i press enter enter in JTextField, the text gets added in JTextPane. Everything works fine and scrollbar too appears on its own. But, it doesn't appear properly. It automatically scrolls to the beginning of the content in JTextPane. How do i keep the scrollbar to the end of JTextPane?

Please let me know if my question is unclear. Thanks in advance :)

+1  A: 

I found a discussion of the same problem. Have a look at http://www.coderanch.com/t/329964/GUI/java/JScrollpane-Force-autoscroll-bottom

Jonas
+1  A: 

You can try by invoking

scrollPane.scrollRectToVisible(new Rectangle(0,main.getBounds(null).height,1,1));

This should be the most working approach. Otherwise try to search out scrollPane.setValue(..) or work with the caret: editorPane.setCaretPosition(...)

Jack
+1  A: 

The provided link in the accepted answer is an old link. You may want to check out Text Area Scrolling for additional information. The entry is for a text area but I believe the information applies to a text pane as well.

camickr
Thanks camickr.
Ankit Rathod