Wow, that was quickly ^^
It works very well. Thank you (both) very much!
2008/11/6 Lothar Kimmeringer <[EMAIL PROTECTED]>
>
> Schimki86 schrieb:
> > I use a KeyboardListener to check the typed character. I've seen this
> > example in the book "GWT in Action":
> >
> > public void onKeyUp(Widget sender, char keyCode, int modifiers) {
> > if (!Character.isDigit(keyCode)) {
> > ((TextBox)sender).cancelKey();
> > return;
> > }
> > }
> >
> > In IE it works but in FF the Listeners is listen to the control-,
> > delete- and backspace- key too. I can't delete an character because
> > these keys are no digits.
>
> This is my implementation after finding out the same:
>
>
> /**
> * KeyboardListener allowing only digits to be entered
> */
> public static KeyboardListenerAdapter OnlyDigitListener = new
> KeyboardListenerAdapter() {
> public void onKeyPress(final Widget sender, final char keyCode,
> final int modifiers) {
> switch(keyCode){
> case KEY_LEFT:
> case KEY_DOWN:
> case KEY_RIGHT:
> case KEY_UP:
> case KEY_BACKSPACE:
> case KEY_DELETE:
> return;
> }
> if (!Character.isDigit(keyCode)) {
> ((TextBoxBase) sender).cancelKey();
> }
> }
> };
>
> Works here. The class is a static inner class, so I can use
> it in all components that need a digit-only textbox. As
> well you can create new anonymous classes that way, to change
> the behavior:
>
> textBox.addKeyboardListener(new OnlyDigitListener(){
> public void onKeyPress(final Widget sender, final char keyCode, final
> int modifiers) {
> if (keyCode == '.' || keyCode == '-'){
> return;
> }
> super.onKeyPress(sender, keyCode, modifiers);
> }
> }
>
>
> Regards, Lothar
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---