cubrovic
asked on
Display and accept foreign characters (Swing)
I alrerady have this question at
https://www.experts-exchange.com/questions/20716473/Accepting-Unicode-characters-on-forms.html
so it's the same problem of displaying and accepting foreign characters in java swing.
I need some working example (as little as it can be) to try to achieve my goal on this (this should be easy ?!).
https://www.experts-exchange.com/questions/20716473/Accepting-Unicode-characters-on-forms.html
so it's the same problem of displaying and accepting foreign characters in java swing.
I need some working example (as little as it can be) to try to achieve my goal on this (this should be easy ?!).
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for fast response.
When I start your example i see 4 characters that looks like some mathematical symbols (sure no serbian).
When I copy it from Text Field and paste it in any (unicode capable) program i see
ѠѰҀt 8;
This is also what I see when I use your unicode values to see it from html/javascript (with witch I don't have any problem with any foreign letters)
<html>
šđčć&# 382;<br/>
<script>
var s = "\u0460\u0470\u0480\u0490"
document.write(s)
</script>
</html>
Back to java.
When I change my Keyboard Layout to serbian and write into text field it doesn't write proper characters.
Waiting for further advices.
When I start your example i see 4 characters that looks like some mathematical symbols (sure no serbian).
When I copy it from Text Field and paste it in any (unicode capable) program i see
ѠѰҀt
This is also what I see when I use your unicode values to see it from html/javascript (with witch I don't have any problem with any foreign letters)
<html>
šđčć&#
<script>
var s = "\u0460\u0470\u0480\u0490"
document.write(s)
</script>
</html>
Back to java.
When I change my Keyboard Layout to serbian and write into text field it doesn't write proper characters.
Waiting for further advices.
>>When I start your example i see 4 characters that looks like some mathematical symbols (sure no serbian).
Do you have either of the fonts i used above on your system?
Do you have either of the fonts i used above on your system?
ASKER
Yes this is what I see.Is this what I suppose to see?
Here is some serbian characters but EE will probably will encode this into some escape sequences.
šðè枊ÐÈÆŽ
If the display is like it suppose to be how can I now accept foreign (serbian) characters from the keyboard.
Here is some serbian characters but EE will probably will encode this into some escape sequences.
šðè枊ÐÈÆŽ
If the display is like it suppose to be how can I now accept foreign (serbian) characters from the keyboard.
This is Serbian AFAIK
tf.setText("\u0452\u0458\u 0459\u045A \u045B\u04 5F");
tf.setText("\u0452\u0458\u
Ensure you set your locale appropriately.
ASKER
OK it displays characters well (cyrilic instead of latin but that's ok).
But I still have problem when I try to accept this characters from the keyboard.
When I copy those characters for some unicode text file to this textField it displays it ok but when I try to write it directly from the keyboard it display some (asci like) wrong characters.
My language isn't set on serbian because of I dont have it in my list so I chose some (any) other language I have (Finland) and then set keyboard Layout to serbian (cause I have that on keyboard layouts) and that works well in any comercial programs I have but not in my java code.
What can I do to make this work now.
But I still have problem when I try to accept this characters from the keyboard.
When I copy those characters for some unicode text file to this textField it displays it ok but when I try to write it directly from the keyboard it display some (asci like) wrong characters.
My language isn't set on serbian because of I dont have it in my list so I chose some (any) other language I have (Finland) and then set keyboard Layout to serbian (cause I have that on keyboard layouts) and that works well in any comercial programs I have but not in my java code.
What can I do to make this work now.
Have you set your locale to Serbian?
ASKER
Do you mean locale in windows or something in java.
if you mean in java - no.
if you mean in windows like I said in previous post.
if you mean in java - no.
if you mean in windows like I said in previous post.
In Java - try it
ASKER
Give me little example how to do it (in your example) because I'm not sure how to do this at all.
try:
new Locale("sr");
new Locale("sr");
Give this a try:
Locale.setDefault(new Locale("Serbian (Cyrillic)", "yu"));
or
Locale.setDefault(new Locale("Serbo-Croatian ", "yu"));
Locale.setDefault(new Locale("Serbian (Cyrillic)", "yu"));
or
Locale.setDefault(new Locale("Serbo-Croatian ", "yu"));
ASKER
I will try that now.
But can I make it that my program detect user setting on keybord layout and change Locale in accordiance with it.
But can I make it that my program detect user setting on keybord layout and change Locale in accordiance with it.
Don't think so unless you use JNI. You might try Runtime exec'ing chcp
> But can I make it that my program detect user setting on keybord layout
It may be already, check what the default locale is set to.
It may be already, check what the default locale is set to.
ASKER
Detecting isn't a need but I cant still accept characters in TextField when I call some of yours setDefaultExample()
it dont accept caharcters [];'/ (because there should be serbian characters) but they are not displayed properly except for two caharcters that exist in ascii (šž) and these are also always in latin (not Cyrilic).
it dont accept caharcters [];'/ (because there should be serbian characters) but they are not displayed properly except for two caharcters that exist in ascii (šž) and these are also always in latin (not Cyrilic).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When my system language is set to english it works and displays all the characters from virtual keyboard and when I change it to serbian then the application starts to write bad characters (but better than earlier). Now displayed characters are most similar characters from the asci (displays d instead of serbian characters that looks like d with some extra line)...
ASKER
Ok guys problem is solved.
Problem was my system language which was set to Finnish like I said but with serbian keyboard layout.
I finally set my system language to (real) Serbian and java works as well as other programs and I dont even have to use Locale.setDefault.
This one is closed so thank you very much and I hope you are satisfied with spliiting points to award effort of both of you.
Thanks again.
Problem was my system language which was set to Finnish like I said but with serbian keyboard layout.
I finally set my system language to (real) Serbian and java works as well as other programs and I dont even have to use Locale.setDefault.
This one is closed so thank you very much and I hope you are satisfied with spliiting points to award effort of both of you.
Thanks again.
tf.setFont(new Font("Arial Unicode MS", Font.PLAIN, 12));
String euroSymbol = "\u20ac";
tf.setText(euroSymbol);