【发布时间】:2014-08-20 19:20:29
【问题描述】:
我发现当我在我的 Java swing 应用程序中显示JDialog 或新的JFrame 时,我的中文输入法会在 Windows 7 中从半字节模式切换到全字节模式。
为什么调用对话框或框架setVisible(true) 方法会切换我的IME 设置?
有谁知道代码有什么问题,或者是Java的错误?
重现问题的过程:
- 运行应用程序。
- 将您的语言更改为中文输入法之一,例如。中文(繁体) - 快速
- 点击程序中的按钮
我的语言设置
我发现了一个类似的问题Automatic toggling of character width by Windows 7 input methods in Java
添加默认语言环境后,它仍然无法正常工作
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Locale;
public class MainWindow {
private JFrame frame;
private Locale l;
/**
* Create the application.
*/
public MainWindow() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
l = new Locale("zh", "zh_TW");
frame = new JFrame();
frame.setLocale(l);
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JDialog d = new JDialog(frame, "Run", true);
d.getContentPane().add(new JLabel("dsad"));
d.setMinimumSize(new Dimension(150, 100));
d.setLocationRelativeTo(null);
d.setLocale(l);
d.setVisible(true);
}
});
frame.getContentPane().add(btnNewButton, BorderLayout.CENTER);
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainWindow window = new MainWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
【问题讨论】:
-
@Andrew Thompson 我们大多数人,默认情况下是 IDE 的囚徒(有一些增强功能:-),包括。这个
-
@mKorbel 哦,来吧。您的 IDE 不允许您定义自己的模板吗?如果没有,那就买一个更好的。 ;)
-
@AndrewThompson 我已经向java报告了,但是已经快2周了,没有回复,你能推荐一些关键字让我搜索数据库吗?
-
我首先要搜索的词是“Swing IME”或“Swing 输入法验证”,可能会添加或替换“Locale”(任一词)。
-
顺便说一句-我从
Control Panel找到了我的路|Clock, Language and Region|到Region and Language对话框。但它看起来与上面显示的不同。如何在 Windows 7 上获得该对话框?