首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么设置JDialog或JFrame setVisible(true)会切换输入法设置?

为什么设置JDialog或JFrame setVisible(true)会切换输入法设置?
EN

Stack Overflow用户
提问于 2014-06-30 20:07:39
回答 4查看 1.1K关注 0票数 19

我发现当我在Java swing应用程序中显示一个JDialog或新的JFrame时,我的中文输入法在Windows7中会从半字节模式切换到全字节模式。

为什么调用对话框或frame setVisible(true)方法会切换我的输入法设置?

有没有人知道代码出了什么问题,或者是Java的bug?

重现问题的步骤:

运行application.

  • change
  1. 你的语言到一种中文输入法,例如。中文(繁体)-Quick
  2. 单击程序

中的按钮

我的语言设置

我发现了一个类似的问题Automatic toggling of character width by Windows 7 input methods in Java

在添加了默认语言环境之后,它仍然不能工作

代码语言:javascript
复制
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();
            }
        }
    });
}


}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24489808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档