• Post Reply Bookmark Topic Watch Topic
  • New Topic

UTF-8 format text in swing components.. ? is it possible

 
Phani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have several text douments(UTF-8 format) of different languages.i'm
getting a problem while trying to load that text into
jTextArea(javax.swing package) . i want to know whether the swings
components support multi language font, if please tell me how to solve
my problem
http://mail.google.com/mail/?ui=2&ik=1bf8102429&realattid=f_f98yllbe0&attid=0.1&disp=inline&view=att&th=116619c9bf7bda52

description of the above link :

langauge loaded is Tamil , java.awt.TextArea is able to show that font
where as javax.swing.JTextArea is not supporting
I just want to use javax.swing.JTextArea , can i use that in such conditions .

code :
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new
InputStreamReader(fis , "UTF-8"));
while( (s = br.readLine()) != null)
{
sb = sb.append(s + " ");
}
String[] st = sb.toString().split("\\s");
for(int i = 0 ; i < st.length ; i++)
{
sb2 = sb2.append(st[i] + " ");
}

sb2 is the final string that will be used as jTextArea1.setText(sb2.toSTring());
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Phani:
Hi,

i have several text douments(UTF-8 format) of different languages.i'm
getting a problem while trying to load that text into
jTextArea(javax.swing package) . i want to know whether the swings
components support multi language font


I see nobody has answered so I'll give it a shot, even though pretty much all my work in English.

Swing comonents do support multiple languages. For the most part there's no API for doing so, it's just a side effect of Java's support for Unicode. Strings in Java are (essentially) UTF-16.

So, if you just try jTextArea1.setText("தமிழ்") does it work? If not, I would guess it's a font issue, not an IO issue, and probably resolved by calling setFont() with a font that you know includes the Tamil characters.

If so, then I guess your IO code is the next place to look. One thing you could try is calling jTextArea1.read(br) instead of looping through the input yourself. Another is using a FileReader instead of wrapping a FileInputStream in a InputStreamReader.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!