Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is It Possible To Set Input Numbers for JTextFiled?

 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are there any samples like this?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a DocumentFilter might be an option, but how are you handling pasting of text?
 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
really didnot think of that
i didnot do such a behaviour before
 
Brian Cole
Author
Ranch Hand
Posts: 899
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic