开发者

GWT: How to center element containing CellTable?

开发者 https://www.devze.com 2023-03-30 02:52 出处:网络
I\'m trying to center an element that contains a CellTable. The actual centering logic works okay, but I\'m having problems with all those

I'm trying to center an element that contains a CellTable. The actual centering logic works okay, but I'm having problems with all those attaching/detaching events. Basically, I'm doing this in my container widget:

@开发者_StackOverflow中文版Override
public void onLoad() {
  super.onLoad();
  center();
}

However, it seems that onLoad on the container does not mean that all children have loaded, so... the actual centering routine is called too early and Element.getOffsetWidth/getOffsetHeight are both returning 0. This results in the container being displayed with the left upper corner in the center of the screen.

Same thing happens if I use an AttachEvent.Handler on the CellTable.

So... is there any event on CellTable, or on Widget or whatever that allows me to trigger an action when the DOM subtree has been attached to the DOM?

Thanks in advance.


Take a look at scheduleDeferred. A deferred command is executed after the browser event loop returns.

Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    @Override
    public void execute() {
        center();
    }
});


Override onAttach instead of onLoad. onAttach default implementation calls onLoad followed by doAttachChildren (which calls onAttach on each child widget), so the following code should call center after the children have been attached:

@Override
public void onAttach() {
  super.onAttach();
  center();
}

(BTW, the default implementation of onLoad is a no-op)

0

精彩评论

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