How to bind a button component with Enter key?

Hello

I have a login panel where by user should enter username and password and click login button. But also I want when user press enter from the keyboard, login button should be invoked too.

In toolkit 4 I used the following code and it worked fine, but not in toolkit 5

public Action[] getActions(Object target, Object sender) {
	 		Action[] actions = new Action[1]
;
	 
	 		// Set the action for the requested component 
	         if (sender == btLogin)
	         {
	         	// Bind the unmodified Enter key to the Ok button. 
	             actions[0]
 = new ShortcutAction("Default key",
	                                             ShortcutAction.KeyCode.ENTER, null);
	         } 	        
	         else
	         	return null;
	 		return actions;
	 	}
		public void handleAction(Action action, Object sender, Object target) {
	 		if (target == btLogin)
	 			this.buttonLogin();	 		
	 	}
	 
	 	public void buttonLogin() 
	 	{
	 		userN = (String)tfUserName.getValue();
			String rawPwd = (String)tfPassword.getValue();
			try
			{
				/**Encrypt a password to get it copared to database encrypted one*/
				String pwd = Utilities.encryptFactory(rawPwd);						
				/**Check if loging information given are correct*/
				if(UserControl.authenticateUser(userN, pwd))
				{..........

Note: buttonLogin() should be the method to handle login process.

Thanks

Hi!

In TK5 keyboard shortcuts are bound to Panel’s (including Window). So attach your action to that and everything ought to be fine.

BTW. If you want to have a login screen that can be used with browsers password managers, I suggest you have a look at a class called LoginForm. It also deals your enter binding.

cheers,
matti