5

I need a custom widget height. I tried using this

Integer.toString(yourWidget.getElement().getOffsetHeight())

but,

  • If I use it when I create it or add it to the container panel, it returns 0
  • If I use it in the contrainer panel's onLoad method, it returns the widget height before the style is applied

So, when should I use it to get the widget height after the style is applied?

Thanks a lot!

Igor Klimer
  • 15,321
  • 3
  • 47
  • 57
david
  • 2,135
  • 4
  • 24
  • 34

3 Answers3

1

I don't known if you've solved your problem already, but an option to use JSNI would be making sure that the widget creation is finished.

A way of achieving that is with the Deferred command:

    DeferredCommand.addCommand(new Command() {
        public void execute() {
            // Ask here for the height
        }
    });
Carlos Tasada
  • 4,438
  • 1
  • 23
  • 26
  • Thx a lot! ir works perfect!, however DeferredCommand now is deprecated, so I used Scheduler.get().scheduleDeferred(new ScheduledCommand() {... – david Mar 14 '12 at 15:03
0

I think onAttach or onLoad would be a good catch..

@Override
protected void onLoad() {
   super.onLoad();
   //do sth
}
markovuksanovic
  • 15,676
  • 13
  • 46
  • 57
  • How about tools like Firebug - do they show the value you expect or does the height stay the same? (there are many ways the CSS can affect the height of an element - not always in the way you'd expect) – Igor Klimer Jul 20 '10 at 08:37
  • I remember I had the same problem a looong time ago.. And just can't remember how it was solved... basically the problem was that i was trying to change height while the widget was still not completely constructed... I-ll try to find the code... – markovuksanovic Jul 20 '10 at 14:46
0

Seems to be the same kind of problem that the one exposed here: GWT - Retrieve size of a widget that is not displayed

They used a workaround using JSNI to do what they wanted, maybe a similiar trick will work for you as well.

Community
  • 1
  • 1
Garagos
  • 588
  • 1
  • 4
  • 16