Thursday, February 14, 2008

java change keyboard layout

Visit the following article http://java.sun.com/products/jfc/tsc/articles/InputMethod/inputmethod.html
and read it carefully.

if you download and copy following jar file to /lib/ext you will have a menu item called "select input method" added to all swing applications.
http://java.sun.com/products/jfc/tsc/articles/InputMethod/InputMethodHotKey.jar

You can find full specification and api document here
http://java.sun.com/javase/6/docs/technotes/guides/imf/index.html

Finally the direct answer is here:
Any swing component which extends from java.awt.Window has a method called getInputContext(). You can change the input method like this, it will automatically change the keyboard layout when you focus the component.
for example"
yourMainJFrame.getInputContext().selectInputMethod(new Locale("fa", "IR"));

3 comments:

Carl said...

thanks, just what I was looking for!

Unknown said...

thank your very much for this useful post.

isau said...

Thanks alot, very useful.