I'm new in Google web toolkit. I should implement a button "enter key" in my project. Can you please help me?
In the login menu there is a click handler, on which the user enters her login information and be able to press "enter" afterward.
Code I have so far:
Button btnLogin = new Button("Login");
btnLogin.addListener(new ButtonListenerAdapter() {
public void onClick(Button button, EventObject e) {
Date date = new Date();
Cookies.setCookie("user", username.getValueAsString(), date);
Cookies.setCookie("pass", password.getValueAsString(), date);
Cookies.setCookie("save_login", checkbox.getValueAsString(), date);
formPanel.getForm().submit("Login", null, Connection.POST, "Logging...", false);
}
});
If you like to submit the data , when the user uses the enter key, just add a KeyUpHandler to your button:
button.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
// do submit form
}
}
});
You should use Handler instead of listener. Listener are old school and starting with GWT 2.0 deprecated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.