Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 701743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:38:37+00:00 2026-05-14T03:38:37+00:00

I have created JTextpane and inserted components inside textpane (components like Jtextarea). (vertical scrollbar

  • 0

I have created JTextpane and inserted components inside textpane (components like Jtextarea). (vertical scrollbar of )Jscrollpane of JTextpane is automatically set to bottom when I insert new components in that JTextpane. I want to keep it to be set to the top position. How can I do this

Thanks
Sunil Kumar Sahoo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:38:38+00:00Added an answer on May 14, 2026 at 3:38 am

    Here’s a utility class I use. It can be used to scroll to the top, bottom, left, right or horizonatal / vertical center of a JScrollPane.

    public final class ScrollUtil {
        public static final int NONE = 0, TOP = 1, VCENTER = 2, BOTTOM = 4, LEFT = 8, HCENTER = 16, RIGHT = 32;
        private static final int OFFSET = 100; // Required for hack (see below).
    
        private ScrollUtil() {
        }
    
        /**
         * Scroll to specified location.  e.g. <tt>scroll(component, BOTTOM);</tt>.
         *
         * @param c JComponent to scroll.
         * @param part Location to scroll to.  Should be a bit-wise OR of one or moe of the values:
         * NONE, TOP, VCENTER, BOTTOM, LEFT, HCENTER, RIGHT.
         */
        public static void scroll(JComponent c, int part) {
            scroll(c, part & (LEFT|HCENTER|RIGHT), part & (TOP|VCENTER|BOTTOM));
        }
    
        /**
         * Scroll to specified location.  e.g. <tt>scroll(component, LEFT, BOTTOM);</tt>.
         *
         * @param c JComponent to scroll.
         * @param horizontal Horizontal location.  Should take the value: LEFT, HCENTER or RIGHT.
         * @param vertical Vertical location.  Should take the value: TOP, VCENTER or BOTTOM.
         */
        public static void scroll(JComponent c, int horizontal, int vertical) {
            Rectangle visible = c.getVisibleRect();
            Rectangle bounds = c.getBounds();
    
            switch (vertical) {
                case TOP:     visible.y = 0; break;
                case VCENTER: visible.y = (bounds.height - visible.height) / 2; break;
                case BOTTOM:  visible.y = bounds.height - visible.height + OFFSET; break;
            }
    
            switch (horizontal) {
                case LEFT:    visible.x = 0; break;
                case HCENTER: visible.x = (bounds.width - visible.width) / 2; break;
                case RIGHT:   visible.x = bounds.width - visible.width + OFFSET; break;
            }
    
            // When scrolling to bottom or right of viewport, add an OFFSET value.
            // This is because without this certain components (e.g. JTable) would
            // not scroll right to the bottom (presumably the bounds calculation
            // doesn't take the table header into account.  It doesn't matter if
            // OFFSET is a huge value (e.g. 10000) - the scrollRectToVisible method
            // still works correctly.
    
            c.scrollRectToVisible(visible);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a PHP-script to update a web server that is live inside
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a UserControl that has a ListView in it. The ListView is
I have created a C# class file by using a XSD-file as an input.
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have created a foreign key (in SQL Server) by: alter table company add
I have created a webservice in .net 2.0, C#. I need to log some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.