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 673191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:34:07+00:00 2026-05-14T00:34:07+00:00

I want to have a JEditorPane inside a JScrollPane. When the user clicks a

  • 0

I want to have a JEditorPane inside a JScrollPane. When the user clicks a button, the click listener will create a textEditor, call jscrollpane.setViewPort(textEditor), call textEditor.setText(String) to fill it with editable text, and call jscrollpane.getVerticalScrollBar().setValue(0). In case you’re wondering, yes, the setText() must come after the setViewPort() for reasons that aren’t on topic.

Here is the problem: After the user clicks the button, the JScrollPane’s view scrolls all the way to the bottom. I want the scrollbar to be at the top, as per the last line in my click listener.

I popped open a debugger, and to my horror, discovered that the jscrollpane’s viewport is being forced down to the bottom after the conclusion of the click listener (when pumping filters). It appears that Swing is delaying the population of the editor/jscrollpane until after the conclusion of the clicklistener, but is calling the scrollbar command first. Thus, the undesired behavior.

Anyway, I’m wondering if there is a clean solution. It seems that wanting a scrollpane to be scrolled to the top after modification would be a reasonably common requirement, so I’m assuming this is a well-solved problem.

Thanks!

  • 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-14T00:34:07+00:00Added an answer on May 14, 2026 at 12:34 am

    Ok, it amazes me how I always figure out the answer fractions of a second after posting.

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            pane.getVerticalScrollBar().setValue(0);
        }
    });
    

    This allows the scrolling action to be delayed until after the other task completes. Question: is this good style/reliable or is it just a race condition? Can I depend on this working?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have an executable file that will call some other programs. The
I want to have a text box that the user can type in that
I want to have a function that will return the reverse of a list
Suppose I have a JEditorPane in a JPanel. I want to be able to
I have a snippet to create a 'Like' button for our news site: <iframe
I want to have a select-only ComboBox that provides a list of items for
I want to have a PHP script send a XML formatted string to another
I want to have a class which implements an interface, which specifies the specific
I want to have a web based admin to upload, delete files and folders
I want to have two items on the same line using float: left for

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.