Some characters are not entering KeyPress event [message #506094] |
Wed, 06 January 2010 04:59 |
|
Hi all,
I'm trying to filter characters typed by users in keyPress event, but it
seems that when you type fast enough, some characters are not passed to
this event at all, hence it's impossible to filter them.
Here's a little snippet to reproduce:
....
Text text = new Text(parent, null);
text.addKeyListener
(
new KeyAdapter()
{
@Override
public void keyPressed(KeyEvent e)
{
System.out.println("char : " + e.character);
}
}
);
....
Just type arbitrary characters fast and expect that some characters
don't show up in the console.
I've tried the same snippet on RCP and it works fine there.
Best Regards,
Setya
|
|
|
Re: Some characters are not entering KeyPress event [message #506109 is a reply to message #506094] |
Wed, 06 January 2010 08:28 |
Ivan Furnadjiev Messages: 2426 Registered: July 2009 Location: Sofia, Bulgaria |
Senior Member |
|
|
Hi Setya,
The current scope of the key event implementation is to provide the
infrastructure necessary to bring Cell Editors to work (see bug 225764
for more details). In order to filter the user input you can use a
verify/modify listener. An example how to allow user to type only
numbers is available in Controls Demo -> TextTab (
org.eclipse.rap.demo.controls.TextTab.java ).
HTH,
Ivan
On 1/6/2010 6:59 AM, Setya wrote:
> Hi all,
>
> I'm trying to filter characters typed by users in keyPress event, but
> it seems that when you type fast enough, some characters are not
> passed to this event at all, hence it's impossible to filter them.
>
> Here's a little snippet to reproduce:
>
> ...
> Text text = new Text(parent, null);
> text.addKeyListener
> (
> new KeyAdapter()
> {
> @Override
> public void keyPressed(KeyEvent e)
> {
> System.out.println("char : " + e.character);
> }
> }
> );
> ...
>
> Just type arbitrary characters fast and expect that some characters
> don't show up in the console.
>
> I've tried the same snippet on RCP and it works fine there.
>
>
> Best Regards,
>
> Setya
|
|
|
Re: Some characters are not entering KeyPress event [message #506115 is a reply to message #506109] |
Wed, 06 January 2010 09:07 |
|
Hi Ivan,
> The current scope of the key event implementation is to provide the
> infrastructure necessary to bring Cell Editors to work (see bug 225764
> for more details). In order to filter the user input you can use a
> verify/modify listener. An example how to allow user to type only
> numbers is available in Controls Demo -> TextTab (
> org.eclipse.rap.demo.controls.TextTab.java ).
Thank you for your pointer.
Initially I was using the same approach as shown by the example, but
then I notice that the invalid character had a chance to show up briefly
and quickly vanished. Since I thought this might confuse users, I
decided to move the character screening in the keyPressed event
especially after Text#getCaretPosition is available.
Can we consider this as a bug/enhancement since the same snippet works
in RCP ?
Best Regards,
Setya
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03176 seconds