Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » VerifyEvent and keycode MacOSX
VerifyEvent and keycode MacOSX [message #57749] Sat, 31 May 2003 23:14
Eclipse UserFriend
Originally posted by: pdrolet.mac.com

Hi,

I have been trying to do some validation of inputs in Text control. I
want that only numbers be allowed. I add a VerifyLister to the control
Here is the code of the listener:


/*
* Created on 2003-04-25
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package ca.infodata.fmedx.listeners;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.apache.commons.validator.*;

/**
* @author pdrolet
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class NumberVerifyListener implements VerifyListener{

static boolean lDone = false;
private static final NumberVerifyListener instance = new
NumberVerifyListener();


// protected NumberVerifyListener(){
// }
/*
* @see
org.eclipse.swt.events.VerifyListener#verifyText(org.eclipse .swt.events.VerifyEvent)


*/
public void verifyText(VerifyEvent e) {
System.out.println("e.text = "+e.text);
System.out.println("e.keyCode = "+String.valueOf((e.keyCode)));
if (!GenericValidator.matchRegexp(e.text,"[0-9]") && !(e.keyCode==SWT.BS)) {
e.doit=false;
}
}

public static VerifyListener getInstance() {
return instance;
}

}


But the keyCode returns 0 all the time. It doe not care which key is
pressed! So if the user wants to delete (with backspace), it does not
work. For example, if I press the 1 key, the console gets:

e.text = 1
e.keyCode = 0

With backspace, it is:
e.text =
e.keyCode = 0

Is-it a bug or I simply do not know how to program this?

Thanks for your input.

Patrice Drolet
--
Patrice Drolet
Logiciels INFO-DATA inc.
Previous Topic:Eclipse for C++? (or Good IDEs for C++)
Next Topic:Calling refresh when a java program ends
Goto Forum:
  


Current Time: Thu Dec 26 21:00:22 GMT 2024

Powered by FUDForum. Page generated in 0.02658 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top