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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For some reason in WinHost I had to log in… May 15, 2026 at 11:52 am
  • Editorial Team
    Editorial Team added an answer Instead of 1 call per question to pull the answers,… May 15, 2026 at 11:52 am
  • Editorial Team
    Editorial Team added an answer With propObj defined as you did, you could do something… May 15, 2026 at 11:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.