1

JTextFieldsを含むフォームがあります。一部はフランス語に固有で、その他はアラビア語に固有です。Alt+Shiftキーを押さずに言語を別の言語に切り替えたい。ソリューションに関するヘルプをいただければ幸いです。ありがとう、

4

2 に答える 2

2

あなたの答えをありがとうaymeric、しかし私は問題の解決策を見つけました、これが私が問題を解決する方法です:

public void Arabe(JTextField txt) {
    txt.getInputContext().selectInputMethod(new Locale("ar", "SA"));
    txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);    
}

public void Français(JTextField txt) {
    txt.getInputContext().selectInputMethod(new Locale("fr","FR"));
    txt.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);    
}

private void txt1_FocusGained(java.awt.event.FocusEvent evt) {                                     
    Arabe(my_textfields1);
}                                    

private void txt2_FocusGained(java.awt.event.FocusEvent evt) {                                        
    Français(mytextfields2);
}          
于 2012-08-17T20:12:39.123 に答える
0

私が質問を理解する方法は、いくつかの特定のテキストフィールドをアラビア語(右から左へ+アラビア文字付き)にし、他のテキストフィールドをフランス語にしたいということです。

ユーザーがALT+SHITを押さないようにすることが主な関心事である場合は、プログラムにユーザーのためにそれを実行させるだけです:)

これは、開始するための単なる例です(まだ解決策が見つからない場合):

public class Test {

    /** 
     * This method will change the keyboard layout so that if the user has 2 languages
     * installed on his computer, it will switch between the 2 
     * (tested with french and english) 
     */
    private static void changeLang() {
        Robot robot;
        try {
            robot = new Robot();
            robot.keyPress(KeyEvent.VK_SHIFT);
            robot.keyPress(KeyEvent.VK_ALT);

            robot.keyRelease(KeyEvent.VK_SHIFT);
            robot.keyRelease(KeyEvent.VK_ALT);
        } catch (AWTException e1) {
            e1.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {

        JFrame f = new JFrame();

        JTextField arabicTextField = new JTextField();
        JTextField frenchTextField = new JTextField();

        f.add(frenchTextField, BorderLayout.NORTH);
        f.add(arabicTextField, BorderLayout.SOUTH);

        frenchTextField.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                changeLang();
            }
        });

        arabicTextField.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                changeLang();
            }
        });

        arabicTextField.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

        f.pack();
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
于 2012-08-16T18:15:58.217 に答える