Combo GWT widget

I am trying to create a custom GWT widget. I choose the composite way to build it. But I have a problem, the widget is not visible on the screen. Here is the composite code for the widgets:

public class LoginPanel extends Composite {

private static final String DEFAULT_STYLENAME = "LoginPanel";

private TextBox nameField;
private PasswordTextBox passField;
private Button loginButton;
private Label errorLbl;
private DecoratedPopupPanel decoratedPopupPanel;

public LoginPanel() {
    nameField = new TextBox();
    passField = new PasswordTextBox();
    loginButton = new Button("Login");
    loginButton.getElement().setId("loginButton");
    errorLbl = new Label();

    Grid grid = new Grid(4, 2);
    grid.setWidget(0,0, errorLbl);
    grid.setWidget(1,0, new Label("Name"));
    grid.setWidget(1,1, nameField);
    grid.setWidget(2,0, new Label("Password"));
    grid.setWidget(2,1, passField);
    grid.setWidget(3,1, loginButton);

    decoratedPopupPanel = new DecoratedPopupPanel();
    initWidget(decoratedPopupPanel);
    //decoratedPopupPanel.setAnimationEnabled(true);
    decoratedPopupPanel.setWidget(grid);
    //decoratedPopupPanel.setAnimationEnabled(true);
    decoratedPopupPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
        public void setPosition(int i, int i1) {
            decoratedPopupPanel.setPopupPosition(Window.getClientWidth()/2, Window.getClientHeight()/2);
        }
    });
}

      

}

In an input class function onModuleLoad()

I have this code:

LoginPanel lp = new LoginPanel();
RootPanel.get().add(lp);

      

When I remove the lines of the LoginPanel

class behind the function initWidget()

, then everything is correct, but the widget is not centered. Can anyone help me?

0


source to share


2 answers


The problem is that PopupPanel

it cannot be used as a "normal" widget because it will not be attached to the parent object, but it is attached to the dom to guarantee it from above. Therefore, using initWidget in the popup does not make sense.

To make this work, you have to put the LoginWidget in the PopupPanel, not the other way around. You can make the PopupPanel a member and add a show method to your LoginPanel that invokes the show on the PopupPanel.



If you do not want the login widget to float regardless of the parent or context in which you are using the Login widget, you should not use the PopupPanel.

+2


source


I believe you should call initWidget last. Otherwise, all handling of "child" elements won't work against.



Give it a try and if it doesn't work I'll try to give the best answer.

0


source







All Articles