how to force a scroll to stay at the top of the pane?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.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.
Last edited by copeg; April 15th, 2010 at 09:50 AM.
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.
Last edited by nasi; April 19th, 2010 at 03:42 AM.