简体   繁体   English

将ActionListener添加到JFormattedTextField

[英]Adding ActionListener to JFormattedTextField

在此处输入图片说明

The image above is six formatted textfield I initialized. 上面的图像是我初始化的六个格式化的文本字段。 I added an ActionListener to each one of the text fields; 我向每个文本字段添加了一个ActionListener but after adding listener to the leftmost textfield, the text inside disappears. 但是将侦听器添加到最左边的文本字段后,里面的文本消失了。 When I delete the listener, the text inside reappears. 当我删除侦听器时,里面的文本会重新出现。

在此处输入图片说明

I've tried to set the minimum weight, width of the columns. 我试图设置最小的重量,列的宽度。 Any idea as to what happened here? 关于这里发生的事情有什么想法吗? Thanks for the help!! 谢谢您的帮助!!

The ActionListener I added to the textfields is as follows, 我添加到文本字段中的ActionListener如下,

   formattedTextField_4.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            formattedTextField_4.setText("");
        }
    });

You are setting the text filed value to empty 您正在将文本字段的值设置为空

formattedTextField_4.setText("");

Therefore every time that text field get focus nothing will be remain in text filed 因此,每次文本字段获得焦点时,文本字段中都不会保留任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM