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.

Results 1 to 9 of 9

Thread: JScrollpane - Force autoscroll to top

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default JScrollpane - Force autoscroll to top

    how to force a scroll to stay at the top of the pane?


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: JScrollpane - Force autoscroll to top

    scrollPane.getVerticalScrollBar().setValue(0);
    // or
    getViewportView().scrollRectToVisible(new Rectnagle(0, 0, 0, 0));
    If that doesn't answer your question, you might want to post a SSCCE* to get better help sooner.

    * SSCCE : Java Glossary

    db

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: JScrollpane - Force autoscroll to top

    thanks but none of them solved my problem. I didn't get how I should work with SSCCE

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: JScrollpane - Force autoscroll to top

    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.

  5. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: JScrollpane - Force autoscroll to top

    Quote Originally Posted by copeg View Post
    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.
    Ah well, that's assuming it's a text component that's contained in the scroll pane.

    @OP: there's a link in my previous post -- click it!

    db

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: JScrollpane - Force autoscroll to top

    Quote Originally Posted by Darryl.Burke View Post
    Ah well, that's assuming it's a text component that's contained in the scroll pane.
    Good point . I just made the assumption based upon the OP's number of other posts with regards to a JEditorPane, but your right that would only work for a text component

  7. #7
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: JScrollpane - Force autoscroll to top

    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.

  8. #8
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: JScrollpane - Force autoscroll to 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

  9. #9
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: JScrollpane - Force autoscroll to top

    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.

Similar Threads

  1. [SOLVED] need help, Problem in JScrollPane
    By sny in forum AWT / Java Swing
    Replies: 5
    Last Post: March 15th, 2010, 07:16 AM
  2. Problem with Brute Force
    By mortis1572 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 14th, 2010, 09:52 AM
  3. JScrollPane
    By MysticDeath in forum AWT / Java Swing
    Replies: 1
    Last Post: February 17th, 2010, 09:21 PM
  4. JTable in JScrollPane
    By alwayslearner in forum AWT / Java Swing
    Replies: 1
    Last Post: January 31st, 2010, 09:24 PM
  5. JTable in JScrollPane
    By alwayslearner in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 29th, 2010, 10:42 AM

Tags for this Thread