How to scroll the contents to bottom by default in JTextPane?

10,280

Solution 1

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

Solution 2

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.

Solution 3

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(...)

Share:
10,280
TCM
Author by

TCM

Updated on June 05, 2022

Comments

  • TCM
    TCM almost 2 years

    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?