This discussion is archived
5 Replies Latest reply: Jun 13, 2010 1:52 PM by 843810 RSS

plz help! can't input other charset in JTextField??

843810 Newbie
Currently Being Moderated
dear fridens! please help me!
I am writing a java application which will run under chinese
environment and accept japanese input. When I test this
function, there are some serious problem happend:
a)run under win2000 platform(chinese version):
1.if the JTextField is added in a JDialogs,japanese character
is correctly accepted.
2.if the JTextField is added in a JFrame(or it's sub component),
the japanese character which I have inputed immediately changed
to some irrespective chinese character.

b)run under win98 platform(chinese version):
the Japanese character can't be accepted at all! the JTextField
just display some nonsensical symbol.

(the IME can input japanese correctly in other windows application)
(my java application can display japanese character well)
I have test the JFC demo--"NotePad" under the j2sdk path,the result
is same as above.
is this JTextComponent's problem?

please tell me how I can input various charset correctly whether the
JTextComponent is added to a JDialogs or JFrame or whether the
application is running under win98 or win2000 platform??
I can input chinese no problem under chinese version .
but why can't input japanese....
does JTextComponent automatically change the inputed data into local
default charset String?if so,What can I do to avoid this?
please help! very thanks!

  • 1. Re: plz help! can't input other charset in JTextField??
    843810 Newbie
    Currently Being Moderated
    Try various fonts with the methods setFont(java.awt.Font) in your swing applications.
  • 2. Re: plz help! can't input other charset in JTextField??
    843810 Newbie
    Currently Being Moderated
    fsato4,thank you for your reply!
    I haven't Japanese font in my os.
    and why JDialog under win2000 can accept japanese input?
    and if I input some text in win2000 notepad,then paste this
    text to JTextComponent added in JFrame,it can display Japanese
    correctlly.
    I think maybe it is the input method soft cause this prblem?
    but this IME work perfectly in all other windows application........
    i am so urgent!
  • 3. Re: plz help! can't input other charset in JTextField??
    843810 Newbie
    Currently Being Moderated
    The following code is used for testing fonts that could support Japanese characters on your OS. Then try the method setFont(java.awt.Font) in your application.
    import java.awt.*;
    public class TestFonts{
    public static void main(String[] args) throws java.lang.Exception{
      String sample = new String(new char[]{(char)0x3042,(char)0x3044});//choose your own characters in the array char[]
      java.awt.Font[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
      int q=0;
       for (int j = 0; j< fonts.length; j++){
           q = fonts[j].canDisplayUpTo(sample);
           if ((q == -1) ||(q == sample.length())){
                    System.out.print(fonts[j].getFamily());
                    System.out.print(" :    ");
                    System.out.println("YES ");
                    System.out.println();
            }       
       }//end of for
    }
    }
  • 4. Re: plz help! can't input other charset in JTextField??
    843810 Newbie
    Currently Being Moderated
    it would be nice if some would actually answer the question. Input problem and has nothing to do with the font as the jTextField is displaying the text fine. cut and paste works too. it will not work with anthy (Japanese input processor) Anthy works with open office, and netscape and any number of other applications.

    Dont talk about a character mapping function as kangi is way too complicated for a character map ( you have to type two characters like ma to get &#12414; and if you want kangi then you have to pick one of these &#39764; for a list of any number of kangi characters from a menu.) Anthy is activated with cntl - space.

    so how do you enable the keyboard input processor for jTextField? this seems like a bug? is it fixed yet?


    My environment is Linux latest java jre, eclipse...

    so could some one answer this or point me to the correct thread
  • 5. Re: plz help! can't input other charset in JTextField??
    843810 Newbie
    Currently Being Moderated
    found the solution,

    the problem has to do with scim anthy, uninstalled this and installed the ibus - anthy and it all works.

    this is the case for ubuntu 10.04 and the java 1.6.0 20