I want to have a JEditorPane inside a JScrollPane. When the user clicks the button, the clicker-listener will create a text editor, call jscrollpane.setViewPort (textEditor), call textEditor.setText (String) to fill it with editable text, and call jscrollpane.getVerticalScrollBar (). SetValue (0). If you're interested, yes, setText () should appear after setViewPort () for reasons that are not relevant to the topic.
Here's the problem: after the user clicks the button, the JScrollPane view scrolls to the end. I want the scroll bar at the top, like the last line in my click listener.
I opened the debugger, and to my horror, I found that the jscrollpane viewport is reset down after the click listener has finished (when filtering). It seems that Swing delays the population of the / jscrollpane editor until it completes the clicker, but first calls the scroll command. Therefore, unwanted behavior.
In any case, I wonder if there is a clean solution. It seems that the desire to scroll the scroll bar at the top after the modification will be a fairly common requirement, so I assume this is a well-resolved problem.
Thanks!
source share