and read it carefully.
if you download and copy following jar file to
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"));