how to force a scroll to stay at the top of the pane?
Printable View
how to force a scroll to stay at the top of the pane?
If that doesn't answer your question, you might want to post a SSCCE* to get better help sooner.Code :scrollPane.getVerticalScrollBar().setValue(0); // or getViewportView().scrollRectToVisible(new Rectnagle(0, 0, 0, 0));
* SSCCE : Java Glossary
db
thanks but none of them solved my problem. I didn't get how I should work with SSCCE
By stay at the top what do you mean (this is where a short compilable example might demonstrate what you wish to accomplish). If scrollRectToVisible does not work, try calling either select(0,0) or setSelectionStart(0) and setSelectionEnd(0) on your text component.
but it doesn't work as well. I upload a text file in jeditorpane but after uploading the scroll bar goes to the bottom of the page I want it to stay at the top.
Wold you like to be more specific so that we don't have to keep on guessing at the details of your problem?
Anyhow, DefaultCaret.setUpdatePolicy(int) may be useful to you. Depending on what you mean by your non-standard use of the word "upload" and whether by jeditorpane you mean JEditorPane.
db
oh my god, it is clear. I just want to keep scroll bar at the top of a JScrollPane which contains a JEditorPane after displaying my text in it. I don't want the user have to scroll up, after opening the file. because as I said when I open my file in JEditorPane the scroll bar goes to bottom. I want in the JEditorPane the user see the begining of the file not its end when the file is opened in it.