Search code examples
javaswinguser-interfacejformattedtextfieldsizing

Adding ActionListener to JFormattedTextField


enter image description here

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.

enter image description here

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("");
        }
    });

Solution

  • 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