How to get the rendered size of a

2019-04-01 01:01发布

I have a FlowPanel, whose height is fixed (it is actually a percentage of its parent's height, which is fixed).
In this panel, I add several div elements. Using CSS, I set its height as 100% of its parent.
What I want to do is set its width to be equal to its height using javascript.

The issue I have is that I don't know when to run this bit of javascript. I tried adding it to the onLoad() method of my container, but the height is not known yet (getOffsetHeight() returns 0).

I had a look at similar questions (like GWT - Retrieve size of a widget that is not displayed), but they were not exactly the same thing.

标签: gwt size
1条回答
Viruses.
2楼-- · 2019-04-01 01:37

Defer the call to getOffsetHeight() until the end of the event loop:

@Override
public void onLoad() {
  Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    @Override
    public void execute() {
      // Get and work with the element's offsetHeight.
    }
  }
}
查看更多
登录 后发表回答