简体   繁体   中英

Adding ActionListener to JFormattedTextField

在此处输入图片说明

The image above is six formatted textfield I initialized. I added an ActionListener to each one of the text fields; 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,

   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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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