aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Is It Possible To Set Input Numbers for JTextFiled? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Is It Possible To Set Input Numbers for JTextFiled?" Watch "Is It Possible To Set Input Numbers for JTextFiled?" New topic
Author

Is It Possible To Set Input Numbers for JTextFiled?

mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
greetings all
i have a JTextField For Inputting numbers only
when trying to input digits,the windos settings is to write in english
so Numbers Are Typed 0123456789
but i want when the user tries to input numbers it's automatically typed in arabic numbers,any ideas how to do that?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Sounds like something I ought to move to the Swing forum . . .

Several ways to do it; you can set up a regular expression to test the text; you might get "\\d*" to work.
You can parse the text into an int then print it back in Arabic script. You could even have a KeyListener or something which listens for keystrokes. But you will probably get better answers on the Swing forum.
mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
are there any samples like this?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
a DocumentFilter might be an option, but how are you handling pasting of text?
mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
really didnot think of that
i didnot do such a behaviour before
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by mahmoud saleh:
i have a JTextField For Inputting numbers only
when trying to input digits,the windos settings is to write in english
so Numbers Are Typed 0123456789
but i want when the user tries to input numbers it's automatically typed in arabic numbers,any ideas how to do that?


First of all, we should be careful with terminology because in
many parts of the world 0123456789 are called "Arabic numerals".
(as opposed to Roman numerals: I, II, III, IV, V, VI, VII, VIII, IX)

But I take it you want to see ٠١٢٣٤٣٥٦٧٨٩ from unicode block 0600?
(For lack of a better name, I'll call these "Arabic Arabic" numerals.)

If so, I'm not sure this best way, but it should work:There shouldn't be any left-to-right vs. right-to-left orientation issues.
[ October 10, 2008: Message edited by: Brian Cole ]

bitguru blog
 
jQuery in Action, 2nd edition
 
subject: Is It Possible To Set Input Numbers for JTextFiled?