Hi Jose, What version of GWT are you using? A fix for alignment attributes went into GWT 2.1.1, so if you are using a prior version they will not work properly.
Thanks, Stephanie On Thu, Apr 14, 2011 at 8:21 AM, Jose Luis Hernandez < [email protected]> wrote: > Hello! > I have a problem with DockPanel. I would like to center DockPanel in > the screen. I have the next class to perform login/password screen. > But when I add the dockPanel to RootPanel, it doen not align CENTER. > Could someone help me??? > Thanks in advance! > Regards! > > public class ZB_app implements EntryPoint { > /** > * The message displayed to the user when the server cannot be > reached or > * returns an error. > */ > /*private static final String SERVER_ERROR = "An error occurred > while > " > + "attempting to contact the server. Please check > your network " > + "connection and try again."; > */ > /** > * Create a remote service proxy to talk to the server-side Greeting > service. > */ > private final GreetingServiceAsync greetingService = GWT > .create(GreetingService.class); > > /** > * This is the entry point method. > */ > public void onModuleLoad() { > RootPanel rootPanel = RootPanel.get(); > rootPanel.setStyleName("dialogVPanel"); > > DockPanel dockPanel = new DockPanel(); > > final VerticalPanel vPanel = new VerticalPanel(); > final HorizontalPanel hPanel1 = new HorizontalPanel(); > final HorizontalPanel hPanel2 = new HorizontalPanel(); > hPanel1.setBorderWidth(15); > hPanel2.setBorderWidth(15); > hPanel1.setSpacing(10); > hPanel2.setSpacing(10); > vPanel.setBorderWidth(15); > > Label titleLabel = new Label("Write the login and > password:"); > titleLabel.setStyleName("gwt-Label"); > vPanel.add(titleLabel); > > final Label loginLabel = new Label("Login:"); > loginLabel.setStyleName("gwt-Label"); > loginLabel.setSize("65px", "19px"); > hPanel1.add(loginLabel); > > final TextBox loginField = new TextBox(); > loginField.setText(""); > loginField.setSize("145px", "19px"); > hPanel1.add(loginField); > vPanel.add(hPanel1); > > final Label passLabel = new Label("Password:"); > passLabel.setSize("65px", "19px"); > hPanel2.add(passLabel); > > final PasswordTextBox passField = new PasswordTextBox(); > passField.setSize("145px", "19px"); > hPanel2.add(passField); > vPanel.add(hPanel2); > > final Button loginButton = new Button("Login"); > loginButton.setStyleName("sendButton"); > loginButton.setSize("65px", "35px"); > vPanel.add(loginButton); > > final Label errorLabel = new Label(); > errorLabel.setStyleName("serverResponseLabelError"); > errorLabel.setSize("351px", "19px"); > errorLabel.setVisible(false); > > dockPanel.add(vPanel, DockPanel.CENTER); > dockPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE); > dockPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); > RootPanel.get("mainContainer").add(dockPanel); > //RootPanel.get("mainContainer").add(errorLabel, 450, 350); > > loginField.selectAll(); > passField.selectAll(); > > // Create a handler for the sendButton and nameField > class MyHandler implements ClickHandler, KeyUpHandler { > /** > * Fired when the user clicks on the sendButton. > */ > public void onClick(ClickEvent event) { > try { > sendNameToServer(); > } catch (Exception e) { > e.printStackTrace(); > } > } > > /** > * Fired when the user types in the nameField. > */ > public void onKeyUp(KeyUpEvent event) { > if (event.getNativeKeyCode() == > KeyCodes.KEY_ENTER) { > try { > sendNameToServer(); > } catch (Exception e) { > e.printStackTrace(); > } > } > } > > /** > * Send the name from the nameField to the server > and wait for a > response. > * @throws Exception > */ > private void sendNameToServer() throws Exception { > errorLabel.setText(""); > final String login = loginField.getText(); > final String pass = passField.getValue(); > > // Then, we send the input to the server. > greetingService.greetServer(login, pass, > new AsyncCallback<Boolean>() > { > public void > onFailure(Throwable caught) { > // Show the > RPC error message to the user > > Window.alert(caught.getMessage()); > > errorLabel.setText(caught.getMessage()); > > errorLabel.setVisible(true); > } > > public void > onSuccess(Boolean result) { > if(result){ > > //errorLabel.setText("Login correcto"); > > ZB_driver dev = new ZB_driver(); > > RootPanel.get("mainContainer").remove(vPanel); > > RootPanel.get("mainContainer").remove(errorLabel); > try > { > > dev.addContainers(); > } > catch (Exception e) { > > e.printStackTrace(); > } > } > else { > > > errorLabel.setText("Usuario errĂ³neo"); > > errorLabel.setVisible(true); > > Window.alert("Usuario erroneo"); > } > } > }); > > //rootPanel.get().add(dev); > } > } > > // Add a handler to send the name to the server > MyHandler handler = new MyHandler(); > loginButton.addClickHandler(handler); > loginField.addKeyUpHandler(handler); > passField.addKeyUpHandler(handler); > } > } > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
