Wednesday, May 23, 2012

GWT - DialogBox.center() doesn't work correctly

There's a table with buttons on my page. There're so much buttons, that I have a scroller to scroll down my table.



Button "onClick" generates a dialog box with scrollpanel, content and a button to close this dialog box. I center it using DialogBox.center(). When I press, let's say the first button in a table, dialog box appears strictly in the center.... but when I scroll down the page and press button in the bottom of my table, my DialogBox still appears in the "old" center...almost above my view. It simply doesn't move down according to my scrollbar position.
I tried to change setPopupPosition(), setPopupPositionAndShow() and so on, but it didn't help.



Is there any ideas what is wrong? Here is some code of my dialog box:



public class MyDialogBox extends DialogBox {

public MyDialogBox(final String caption, final String text) {
setText("Caption: " + caption);

VerticalPanel inner = new VerticalPanel();
Label msg = new Label(text);

Button ok = new Button("Close");
ok.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
MessageTextBox.this.hide();
}
});

inner.add(msg);
ScrollPanel scrollbar = new ScrollPanel(inner);
scrollbar.setSize("640", "480");
VerticalPanel outer = new VerticalPanel();
outer.add(scrollbar);
outer.add(ok);
setWidget(outer);
}
}


And here is how my button call it:



VerticalPanel mainPanel ... //MainPanel with a lot different elements, it contains panel with buttons
VerticalPanel panel ... //Panel with buttons
panel.setViewButtonHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
MyDialogBox dialogBox = new MyDialogBox("Caption", "Some text");
dialogBox.center();
}
});
mainPanel.add(panel);




No comments:

Post a Comment