GWT复合小部件 [英] GWT composite widget
问题描述
我尝试构建自己的GWT小部件.我选择构建它的复合方式.但是我有问题,小部件没有在屏幕上看到.这是复合窗口小部件代码:
I try to build own GWT widget. I select the composite way of build it. But I have problem, the widget didn't see on screen. Here is the composite widget code:
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);
}
});
}
}
在入门类函数 onModuleLoad()
中,我有以下这段代码:
In entry class function onModuleLoad()
I have this peace of code:
LoginPanel lp = new LoginPanel();
RootPanel.get().add(lp);
当我在 initWidget()
函数后面的 LoginPanel
类行中删除时,一切都正确,但小部件未居中.谁能帮我吗?
When I delete in LoginPanel
class rows behind initWidget()
function, then all is right, but widget is not centered. Can anyone help me?
推荐答案
问题是 PopupPanel
不能用作常规"窗口小部件,因为它不会附加到父级,但它将自己附加到dom上,以确保它在顶部.因此,在弹出窗口上使用initWidget毫无意义.
The problem is a PopupPanel
can't be used as a 'normal' widget, because it won't be attached to a parent but it attaches itself to the dom to make guarantee it's on top. So using initWidget on a popup doesn't make sense.
要执行此操作,应将LoginWidget放在PopupPanel中,而不要反过来.您可以将PopupPanel设置为成员字段,然后将方法show添加到LoginPanel中,以在PopupPanel字段上调用该显示.
To make this work you should put the LoginWidget in the PopupPanel instead of the other way around. You could make the PopupPanel a member field and add a method show to your LoginPanel that calls the show on the PopupPanel field.
如果您不希望登录小部件独立于您正在使用登录"小部件的父级或上下文浮动,则不应使用PopupPanel.
If you don't want the login widget to float independent of a parent or context you're using the Login widget in, you shouldn't use a PopupPanel.
这篇关于GWT复合小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!