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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:18:12+00:00 2026-05-21T07:18:12+00:00

I am calling com.google.gwt.user.client.ui.TextArea.setText(myText) to set the content. After that I call setCursorPosition(myText.length()) to

  • 0

I am calling com.google.gwt.user.client.ui.TextArea.setText(myText) to set the content. After that I call setCursorPosition(myText.length()) to get the cursor to the end. This works well.

When myText has more lines then the text area can display at once, it shows a scroll bar. But it does not scroll to the cursor position. Even worse – it scrolls to the top.

How can I scroll the GWT TextArea to the cursor position? I realy need the cursor position, not the bottom of the TextArea. A JSNI workaround would be ok too.

  • 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-21T07:18:12+00:00Added an answer on May 21, 2026 at 7:18 am

    I had a scenario where the textarea will already have something and when a new command is submitted it will add the data to it and scroll to the start of the newly added data. this is what I did

        // Hold the previous height to set the scroll.
        final int prevHeight = document.get().getElementById(textareadid).getScrollHeight();
        // Hold the prev position if output area already has some data.
        final int prevPos = this.textArea.getValue() != null ?  
        this.textArea.getValue().length() : 0;
    

    after processing and setting the new data

            int posCount = 0;
            if (previousResponse != null && !previousResponse.isEmpty())
            {
                final String dataStr = "new data from process";
                // add 15 lines for the cursor position
                posCount = getRelativeCount(dataStr);
            }
            this.textArea.getElement().setScrollTop(prevHeight);
            this.textArea.setCursorPos(prevPos + posCount);
    
     private int getRelativeCount(final String str)
    {
        int charCount = 0;
    
        if (str != null)
        {
    
            int NUM_ROWS = 15;
    
            if (getUserAgent().contains("msie"))
            {
                NUM_ROWS = 16;
            }
    
            final String[] splitArr = str.split("\n"); // split on the new line
                                                       // char
    
            for (int index = 0; index < splitArr.length && index < NUM_ROWS; index++)
            {
                charCount += splitArr[index].length();
            }
        }
        return charCount;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some debugging,I found com.google.gwt.event.shared.UmbrellaException:One or more exceptions caught, see full set in UmbrellaException#getCauses'
After calling to a com component procedure , an error raised OLE error C0000094.
I'm using the GSON library and calling the fromJson() method: http://google-gson.googlecode.com/svn/tags/1.2.3/docs/javadocs/com/google/gson/Gson.html My old code:
The MustangPeak Common Library (http://code.google.com/p/mustangpeakcommonlib/) contains the following code that converts a method to
so I'm using google's minify to minify css: http://code.google.com/p/minify/ what I notice is that
Errors while calling int getopt function from http://code.google.com/p/darungrim/source/browse/trunk/ExtLib/XGetopt.cpp?r=17 `check.cpp: In function ‘int main()’:` check.cpp:14:55:
I'm calling the following URL using YQL http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=cbfunc this returns the following in JSON
I'm calling a web API exposed by TheyWorkForYou (TWFI). http://www.theyworkforyou.com/api/ I'm using the Python
I'm looking at the http://digitalbush.com/projects/masked-input-plugin/ I'm calling it like this: $(control).mask('999-999-9999'); And I don't
Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function

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.