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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:38:39+00:00 2026-06-07T07:38:39+00:00

public class AutoResizeBox extends RichTextArea { public AutoResizeBox() { set(getElement()); } public static native

  • 0
public class AutoResizeBox extends RichTextArea
{
    public AutoResizeBox()
    {
       set(getElement());
    }

   public static native void set(Element f) /*-{
       console.log(f.tagName) ;
         // console.log(f.document.body.scrollHeight + 'px');
   }-*/;
}

RichTextBox is based on iframe,I tried to use JSNI.For above code,”console.log(f.tagName)” will print out “IFRAME”,but “console.log(f.document.body.scrollHeight + ‘px’);” will preduce a compilation error:”
com.google.gwt.core.client.JavaScriptException: (TypeError): f.document is undefined”, can anybody tell me reasons?

  • 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-06-07T07:38:41+00:00Added an answer on June 7, 2026 at 7:38 am

    Blow is a worked version

    import com.google.gwt.dom.client.BodyElement;
    import com.google.gwt.event.dom.client.BlurEvent;
    import com.google.gwt.event.dom.client.BlurHandler;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.user.client.DOM;
    import com.google.gwt.user.client.Event;
    import com.google.gwt.user.client.ui.RichTextArea;
    import com.google.inject.Inject;
    
    public class AutoResizeTextArea extends RichTextArea implements ClickHandler,
         BlurHandler
    {
    private static final int margin = 6;
    private BodyElement body;
    private String defaultText;
    private int minHeight = 25;
    private String title;
    
    @Inject
    public AutoResizeTextArea()
    {
        addBlurHandler(this);
        addClickHandler(this);
        setHeight(minHeight + "px");
        setStyleName("textArea");
        sinkEvents(Event.ONKEYUP | Event.ONKEYPRESS);
    }
    
    private void adjustHeight()
    {
        // NP remove blow will cause auto-grow doesn't work
        if (body != null)
        {
            int offsetHeight = body.getOffsetHeight();
            if (offsetHeight != body.getClientHeight())
            {
                int height = (offsetHeight < minHeight ? minHeight : offsetHeight);
                boolean breaking = height > minHeight;
                if (breaking)
                {
                    height = height + margin * 2;
                }
                setHeight(height + "px");
            }
        }
    }
    
    public void clean()
    {
        setText(defaultText);
        setHeight(minHeight + "px");
        setBodyStyle(true);
    }
    
    @Override
    public String getHTML()
    {
        // AP RichTextArea.getHTML will return "<br>",even no html exists
        // within it,report this issue to gwt team;
        String html = super.getHTML();
        return html.equals("<br>") || html.equals(defaultText) ? "" : html;
    }
    
    @Override
    public String getText()
    {
        String text = super.getText();
        return text.equals(defaultText) ? "" : text;
    }
    
    @Override
    public void onBlur(BlurEvent event)
    {
        if (defaultText != null && "".equals(getText()))
        {
            setDefaultText(defaultText);
            setBodyStyle(true);
        }
    }
    
    @Override
    public void onBrowserEvent(Event event)
    {
        super.onBrowserEvent(event);
        int eventType = DOM.eventGetType(event);
        if (eventType == Event.ONKEYUP || eventType == Event.ONKEYPRESS)
        {
            adjustHeight();
        }
    }
    
    @Override
    public void onClick(ClickEvent event)
    {
    
        super.setText(null);
        setBodyStyle(false);
    }
    
    private native void registerOnCut(BodyElement element) /*-{
        var that = this;
        console.log("registerOnCut");
        element.oncut = $entry(function(event) {
            that.@com.athena.client.ui.richtextbox.AutoResizeTextArea::adjustHeight()();
            return false;
        });
        element.onpaste = $entry(function(event) {
            that.@com.athena.client.ui.richtextbox.AutoResizeTextArea::adjustHeight()();
            return false;
        });
    }-*/;
    
    private void setBodyStyle(boolean useDefaultTextStyle)
    {
        if (body != null)
        {
            body.setAttribute(  "style",
                                (useDefaultTextStyle ? "color: gray;font-style: italic;" : "")
                                        + "word-wrap:break-word;overflow:hidden;margin: "
                                        + margin
                                        + "px;padding: 0;font-size: 13px;font-family: arial,\"Microsoft YaHei\", Verdana, Tahoma, Arial, STHeiTi,sans-serif, Simsun;");
        }
    }
    
    public void setDefaultText(String defaultText)
    {
        super.setText(this.defaultText = defaultText);
    }
    
    
    @Override
    public void setHTML(String html)
    {
        super.setHTML(html);
        if (html == null || "".equals(html))
        {
            setDefaultText(defaultText);
        }
        adjustHeight();
    }
    
    
    public void setMinHeight(int minHeight)
    {
        setHeight((this.minHeight = minHeight) + "px");
    }
    
    @Override
    public void setText(String text)
    {
        super.setText(text);
        if (text == null || "".equals(text))
        {
            setDefaultText(defaultText);
        }
    }
    
    @Override
    public void setTitle(String title)
    {
        this.title = title;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected
public class Employee { public static void main(String[] args) { int j=3; staples[] stemp
public class InterruptedInput { public static void main(String[] args) { InputThread th=new InputThread(); //worker
public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class IdAsync extends AsyncTask<String, Void, Void> { AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); protected
public class Demo { public static void main(String args[]) { double d = 12.345;
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private

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.