本文介绍了在java swing应用程序中更改IME语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Java(Swing)中构建一个文本编辑器,其中包含一个用于键入文本的EditorPane和一个包含JRadioButtonMenuitems的菜单。喜欢菜单是语言,语言下的JRadiobuttonMenuitems是西班牙语,日语,英语等,场景是当用户点击并选择任何JRadioButtonMenuItem时系统必须根据所选语言更改其IME。
如果用户点击并选择日语选项,则编辑必须将IME更改为日语以获取当前流程,并允许用户以相应的语言输入文本。

I am building a Text Editor in Java(Swing) having an EditorPane to type the text and a Menu containing JRadioButtonMenuitems. Like Menu is "Language" and JRadiobuttonMenuitems under "Language" are "Spanish","Japanese","English" etc the scenario is that when user clicks and select any JRadioButtonMenuItem the system must change its IME as per the selected language.Like if user click and select Japanese option Editor must change the IME to Japanese for current process and allow user to enter text in respective language.

我是安装了正确的IME。手动我可以改变IME并能够在swing组件中写入。但我的问题是如何以编程方式加载IME。

I've got the proper IME installed. Manually I can change the IME and able to write in a swing component. but my problem is how to load the IME programmatically.

目前我正在windowsXP上构建此应用程序,但希望此应用程序更改每个操作系统的IME语言。

Currently i am building this application on windowsXP but want this application to change IME language for each operating system.

我有谷歌但没有找到任何相关信息来改变IME。

I have google it but havenot found any related information to change IME.

谢谢

推荐答案

通过获取一个InputContext实例并覆盖JEditorPane的getInputContext方法,可以为JEditorPane更改IME语言。

IME Language can be changed for the JEditorPane by getting an InputContext instance and overriding getInputContext method for JEditorPane like.

final InputContext context = InputContext.getInstance();

jEditorPaneMain = new javax.swing.JEditorPane()
   {
       @Override
        public InputContext getInputContext() {
             return context;
        }
   };

以及选择任何语言,例如点击日语JRadioButtonMenuItem添加一个ActionListener

and on selection of any language like on click of japanese JRadioButtonMenuItem add an ActionListener

jRadioButtonMenuItemJapanese.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItemJapaneseActionPerformed(evt);
            }
        });

在事件处理程序中执行以下操作。

do the following inside event handler.

private void jRadioButtonMenuItemJapaneseActionPerformed(java.awt.event.ActionEvent evt) {
      context.selectInputMethod(Locale.JAPANESE);

}

我在Windows XP上试过这个。它的工作非常好。

I have tried this out on Windows Xp. Its working perfectly fine.

这篇关于在java swing应用程序中更改IME语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:31