문제

I have a JTree and I want it to scroll down to the latest child entry.

I used scrollPathToVisible in the following manner

statusTree_.scrollPathToVisible(new TreePath(childNode.getPath()));

Where childNode is the latest added child to the tree. The problem I have is whenever root is added then the scroll does not move down when the first child is added, but starts moving down only from the second child.

User can observe that there is a gap below in the scroll pane and needs to scroll manually, I need the scroll to move automatically for the first child also.

도움이 되었습니까?

해결책

Try to wrap the scrollPathToVisible call in SwingUtilities.invokeLater() to let all listeners to process add node event and refresh internal structures accordingly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top