How to detect if a View is fully rendered?

825 views Asked by At

I have a couple of GWT widgets which are displayed in a view.

The view contains content like this:

FlowPanel mainPanel = new FlowPanel();
RootPanel.get().add(mainPanel);
Label label = new Label("test");
mainPanel.add(label);
FlowPanel otherPanel = new FlowPanel();
mainPanel.add(otherPanel);

The mainPanel gets its final height after the view has been fully rendered. I need to get the value of height from the mainPanel after the render process is completed.

Here is what I do so far:

    new Timer() {

        @Override
        public void run() {
            int height = $(mainPanel).height();
            // do something with the mainPanel height
        }
    }.schedule(300);    

Noite: $(mainPanel) is the use of GWTQuery. I set a timer to hope that the view render process is completed when the timer fires. I suppose this is not a very clever solution.

How can I detect if the view is fully rendered in order to get the final height of the mainPanel?

Edit:

I also tried to use:

@Override
protected void onReveal() {
    super.onReveal();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            // get mainPanel height is incorrect
        }
    });
}

but it seems that the rendering was not completed so the mainPanel did not have the correct height.

Edit:

It seems that the Scheduler works different on mobile and desktop when using SDM. I created a demo project (https://github.com/confile/GWT-2.7-Scheduler-Test) to show the problem.

I created another question for this issue here: https://stackoverflow.com/questions/27128787/gwt-2-7-scheduler-works-different-on-mobile-and-desktop-in-sdm

3

There are 3 answers

0
Abhijith Nagaraja On BEST ANSWER

Gwt itself gives you a hook to do it. It is onLoad(). You can override it.

Example. If you want to know when widgets of a FlowPanel are rendered, you can use

FlowPanel flowPanel = new FlowPanel(){
                      @Override
                      protected void onLoad()
                      {
                        //Do your stuff here
                      }};
6
Andrei Volgin On

You should use a Scheduler, not Timer. See GWT: Timer and Scheduler Classes, which explains the distinction.

UPDATE:

Also, what is $(mainPanel)? You should do:

 int height = mainPanel.getOffsetHeight();
2
Jack Shultz On

This was posted in How to detect if a page has fully rendered using jQuery?

$(window).load(function() {
    //everything is loaded
});