学习java gui的过程中发现自己写的程序,文本输入框会出现问题,似乎是与输入法候选框有关,想咨询一个解决办法

各位问一下,我在用eclipse学java gui的时候,学习过程中换了一台电脑,然后把之前workplace里的项目全都复制了过来,结果程序虽然能运行,但是发现gui窗口只要是有允许输入文字的地方,输入英文还好,输入中文就会出问题(如图),没换电脑之前是没有这个问题的,个人感觉是输入法的候选框引起的问题,但百度了也没发现相关的帖子,所以来问一下。之前的eclipse是2019年版本的,现在的是2021版本,jdk也从13变到了16.


package gui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextArea;

class Frame13 extends JFrame implements ActionListener
{
    private JTextArea ta=new JTextArea(10,20);
    private JFileChooser jfc=new JFileChooser(new File("."));
    private JButton open,save;
    
    public Frame13(String str)
    {
        super(str);
        this.open=new JButton("打开");
        save=new JButton("保存");
        this.setLayout(new FlowLayout(FlowLayout.CENTER,15,10));
        add(ta);
        add(open);
        add(save);
        open.addActionListener(this);
        save.addActionListener(this);
        this.setVisible(true);
        setSize(300,280);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        JButton bt=(JButton) e.getSource();
        if(bt==open)
        {
            int status=jfc.showOpenDialog(this);
            if(status==JFileChooser.APPROVE_OPTION)
            {
                try {
                        File file1=jfc.getSelectedFile();
                        Scanner sc=new Scanner(file1);        
                        String info="";
                        while(sc.hasNext())
                        {
                            String str=sc.nextLine();
                            info+=str+"\r\n";
                        }
                        ta.setText(info);
                        sc.close();
                    }
                catch(Exception error)    
                {
                    
                }
            }
            else    
            {
                ta.setText("没有选择文件");
            }
        }
        else
        {
            int status=jfc.showSaveDialog(this);
            if(status==JFileChooser.APPROVE_OPTION)
            {
                try
                {
                    File file2=jfc.getSelectedFile();
                    BufferedWriter bw=new BufferedWriter(new FileWriter(file2));
                    bw.write(ta.getText());
                    bw.close();
                    
                }
                catch(Exception error)
                {
                    
                }
                
            }
            else
            {
                
            }
        }
    }
    
}
public class GUI_2_3 {//15.5

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Frame13 frame=new Frame13("test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}

这个是英文的,正常
img
这些是一开始运行没问题,输入法候选框一出来后就这样了

img

img

img

我试了下,百度输入法没得问题,难道是输入法的锅?

換輸入法

今天跟你产生了同样的问题,原本是在机房用笔记本电脑自带键盘输入,没有产生问题。后来,回宿舍插上机械键盘后,产生同样的问题,拔下键盘后,用笔记本的键盘输入,又恢复了正常。

解决了吗博主 我也遇到这个问题了应该怎么弄呢

解决了吗博主,我也遇到这个问题了