I have this JTextPane
(wrapped in a JScrollPane
) that is backed by a HTMLEditorKit
. The contents of the JTextPane
is simple HTML with some images (local files) embedded using img tags. The problem is that when you load the the JTextPane
, it takes a split second to load and then it comes up with the scroll bar at the bottom of the page. If I do:
JTextPane text = new JTextPane();
JScrollPane scroll = new JScrollPane(text);
// do some set up...
scroll.getVerticalScrollBar().setValue(0);
it sets the scroll bar momentarily and then another thead (presumably that is in charge of loading the images) comes and knocks the scroll bar back to the bottom. I tried adding:
((AbstractDocument)text.getDocument()).setAsynchronousLoadPriority(-1);
but that did not fix it. Is there any way to get an event from either text.getDocument()
or text
that will notify me when the pane is finished loading so that I can set the scroll bar then? The alternative is that I set up another thread to wait a second or so, and then set the scroll bar, but this is a bad hack.
Your suggestions?