开发者

GWT custom widgets height

开发者 https://www.devze.com 2023-01-07 19:03 出处:网络
I need a custom widget height. I tried using this Integer.toString(yourWidget.getElement().getOffsetHeight())

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 me开发者_C百科thod, 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!


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
        }
    });


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.


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

@Override
protected void onLoad() {
   super.onLoad();
   //do sth
}
0

精彩评论

暂无评论...
验证码 换一张
取 消