1

In a gui I created I have a JEditorPane that has the following operations during class construction:

    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    htmlPane.setContentType("text/html");
    htmlPane.setText(Utils.startHtml);

Then during create GUI I do this:

jsp = new JScrollPane( htmlPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
        jsp.getViewport().setPreferredSize(new Dimension((width/2)+100,height-85));
        rightPanel.add(jsp);

When I load new text into the JEditorPane via set text is scrolls to the botom:

htmlPane.setText(newHtml)

How do I prevent the scrolling to the bottom? I want the top of the html shown.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Pete B.
  • 3,188
  • 6
  • 25
  • 38
  • not sure if is caused by setText, insert or append, from this code description, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable with hardcoded value for `Document` for `JEditorPane` instead of `setText()` – mKorbel Aug 14 '13 at 16:11
  • [don't use setXXSize, ever](http://stackoverflow.com/a/7229519/203657) – kleopatra Aug 14 '13 at 16:19

1 Answers1

2

Try

DefaultCaret caret = (DefaultCaret)htmlPane.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
Reimeus
  • 158,255
  • 15
  • 216
  • 276