Can I change language by JTextField gained focus(Java)

by Tlipre
5 replies
I create some application by using java UI. And I want to change language when I focus on other JTextField.

EX.


When I focus on JTextField upper. Language will switch to English. But when I focus on JTextField lower. Language will switch to other language.

Ps. I come from country where don't use English is Official language.
If I use wrong word or wrong tense. Please provide me a correct word.
Thank you
#change #focusjava #gained #jtextfield #language
  • Profile picture of the author Brandon Tanner
    I don't think you'll find very many people that know Java around here. Might try one of the Java forums...

    java forum - Google Search
    Signature

    {{ DiscussionBoard.errors[8426141].message }}
    • Profile picture of the author Tlipre
      Thank you for advice.
      {{ DiscussionBoard.errors[8426459].message }}
  • Profile picture of the author Valdor Kiebach
    I am learning Java for Android development.
    I think you will have to change the locale by using .selectInputMethod(new Locale())like this for french:

    Code:
    txt.getInputContext().selectInputMethod(new Locale("fr","FR"))
    InputMethod (Java Platform SE 7 )
    {{ DiscussionBoard.errors[8430495].message }}
    • Profile picture of the author IdeaBox
      Originally Posted by Valdor Kiebach View Post

      I am learning Java for Android development.
      I think you will have to change the locale by using .selectInputMethod(new Locale())like this for french:

      Code:
      txt.getInputContext().selectInputMethod(new Locale("fr","FR"))
      InputMethod (Java Platform SE 7 )
      You're correct, that should work. How are you liking Android Dev?
      {{ DiscussionBoard.errors[8430533].message }}
      • Profile picture of the author Valdor Kiebach
        I have managed to get this working, what you need is to set your chosen languages at the start, i put this after the
        Code:
        public static void main(String[] args) {
        you will need to make these for any languages you want to use, I chose German:
        Code:
        final InputContext de = InputContext.getInstance();
        de.selectInputMethod(new Locale("de", "DE"));
        Then when setting up the texfield you set your chosen keyboard layout (language) for this texfield like this
        Code:
        final JTextField mssg = new JTextField(){     
               @Override
                public InputContext getInputContext() {
                return de;
              };
            };
        What this does is makes the texfield called 'mssg' use the German keyboard layout.

        Also you need
        Code:
        import java.awt.im.InputContext;
        import java.util.Locale;

        @IdeaBox

        Yes I am enjoying the Android dev but learning Java is the tricky part.
        I have been using phonegap / cordova with html5 in a webview at the moment but might as well learn Java in my spare time.
        {{ DiscussionBoard.errors[8431282].message }}

Trending Topics