algiogia
algiogia

Reputation: 955

GWT DialogBox auto resize

I have an application with some pop-ups, for which I'm using GWT DialogBox. The content of the pop-ups can change so I need to adapt the size of the pop-up to the content. I was initially setting the height of the pop-up on creation, but then the content would show outside it if bigger. Removing the setHeight, the pop-up actually adapts itself to the content, but I'm having problems centering the pop-up. When the content changes I call popup.center(), but it is not really being centered as when I set manually the height.

I think it's a timing problem, because I have added a listener to center the popup when the window is resized and in this case the pop-up is being properly centered.

Any ideas?

UPDATE: think I found the issue. The content of the pop-up includes a table. The ResizeEvent is fired BEFORE the content of the table is shown, so on centring is actually considering the size of an empty table. I tried to add a LoadingStateChangeHandler to fire a ResizeEvent when the status is LOADED, but it's still firing too early.

Upvotes: 2

Views: 2188

Answers (1)

Vjeetje
Vjeetje

Reputation: 5384

The problem is that the new size of the widget hasn't been calculated when you call popup.center(). Most people use this as a solution:

// <- popup content changes here
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    public void execute() {
        popup.center();
    }
});

Upvotes: 2

Related Questions