Rather than mucking around with key listeners, you could create a Document subclass which only stores English characters.  This allows for handling typing as well as pasting, etc. all in one place.
 
 
I'm not that familiar with Unicode, but lower ASCII values may not be the only English characters in the character set.  Are you specifically trying to limit yourself to ASCII characters?  Why?
 
Swing also has a way of attaching validators to text (and possibly other?) components, but I'm not familiar with it.  You can probably learn about it through either the Java Tutorials at http://java.sun.com/docs/books/tutorial/index.html or The Swing Connection at http://java.sun.com/products/jfc/tsc/index.html.
 
Joel
 
-----Original Message-----
From: Bharat [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 27, 2001 1:08 AM
To: Bharat; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: How to restric japanese characters

Hi folks,
 
First, I must thank you for all ur responses.
I have come to a solution which is working so far.
 
I have added a keylistener to my JtextField which is validating each character which is typed or pasted in the textfiled.
I have written following code to check if the character is non english.
 public static boolean isNonEnglishChar(char c)
 {
  int i = (int) c;
  System.out.println("char " +c +" =" + i);
  if( (i<32) || ( i>126))
   return true;
  
  return false;
 }
 
Comments ???
 
- bharat
----- Original Message -----
From: Bharat
Sent: Wednesday, September 26, 2001 9:29 AM
Subject: How to restric japanese characters

Hi folks,
 
I want my JTextField to accept only english characters and it should reject japanese(or any other language) characters.
Is there any api to do it?  or a sample code which will help ?
 
Thanks,
- bharat
 

Reply via email to