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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:57:31+00:00 2026-05-27T16:57:31+00:00

How to write a widget which reacts on resizing? The following does not work.

  • 0

How to write a widget which reacts on resizing?

The following does not work. onResize() called only once at the beginning. Latter changing browser windows size does not cause this method to be called, despite the fact that DIVs are resized.

public class MyWidget extends SimpleLayoutPanel {

private Label label;

public MyWidget() {
    label = new Label("A");
    add(label);
}

@Override
public void onResize() {
    super.onResize();
    int width = label.getElement().getClientWidth();
    int height = label.getElement().getClientHeight();
    int fontsize = (width>height?height:width);
    if( fontsize > 0 ) {
        DOM.setStyleAttribute(label.getElement(), "font-size", Integer.toString(fontsize)+"px");
    }
}

}

and main module

public void onModuleLoad() {

    MyWidget myWidget = new MyWidget();
    DOM.setStyleAttribute(myWidget.getElement(), "position", "fixed");
    DOM.setStyleAttribute(myWidget.getElement(), "top", "0px");
    DOM.setStyleAttribute(myWidget.getElement(), "left", "0px");
    DOM.setStyleAttribute(myWidget.getElement(), "bottom", "0px");
    DOM.setStyleAttribute(myWidget.getElement(), "right", "0px");

    RootPanel rootPanel = RootPanel.get();
    rootPanel.add(myWidget);


}

UPDATE 1

Version based on ResizComposite also does not work. In this case onResize never called at all.

public class MyWidget extends ResizeComposite  {

private Label label;

public MyWidget() {
    label = new Label("A");
    DOM.setStyleAttribute(label.getElement(), "position", "fixed");
    DOM.setStyleAttribute(label.getElement(), "top", "0px");
    DOM.setStyleAttribute(label.getElement(), "left", "0px");
    DOM.setStyleAttribute(label.getElement(), "bottom", "0px");
    DOM.setStyleAttribute(label.getElement(), "right", "0px");

    SimpleLayoutPanel simpleLayoutPanel = new SimpleLayoutPanel();
    simpleLayoutPanel.add(label);

    initWidget(simpleLayoutPanel);
}

@Override
public void onResize() {

    int width = label.getElement().getClientWidth();
    int height = label.getElement().getClientHeight();
    int fontsize = (width>height?height:width);
    if( fontsize > 0 ) {
        DOM.setStyleAttribute(label.getElement(), "font-size", Integer.toString(fontsize)+"px");
    }

    super.onResize();
}

}

  • 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-27T16:57:32+00:00Added an answer on May 27, 2026 at 4:57 pm

    You have to add to a ProvidesResize widget (RootLayoutPanel, ResizeLayoutPanel) or a HeaderPanel for the RequiresResize to be honored. See http://code.google.com/webtoolkit/doc/latest/DevGuideUiPanels.html#Resize

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

Sidebar

Related Questions

Write a class ListNode which has the following properties: int value; ListNode *next; Provide
I just started to learn Android, I'm trying to write a widget which is
I am trying to write a web widget which will allow users to display
I'm trying to write a lightweight html/javascript widget which lets me colour each character
I'm trying to write a COM++ object wrapper around a Qt widget (control) I
If I name a widget in Interface Builder, and then I write a method
If I write an application in java, does it use native widgets if run
i have the following pgm which responds with a Toast with an incoming msg
Ok, here is the question. Imagine I have a ModelForm which have only two
I am learning Python and PyGTK. I'm trying to write a Twitter client. Which

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.