0

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("");
        }
    });
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
jensiepoo
  • 571
  • 3
  • 9
  • 26
  • Where are you adding this `FocusListener`? If it's inside the constructor, try it adding in the `WindowOpened` or something of the JFrame. My *assumptions* is that this focus gained is called when the text field is created. – Praneeth Peiris Aug 12 '14 at 09:44
  • 1
    because inside your focusgained method you are setting the text value to empty string – Thusitha Thilina Dayaratne Aug 12 '14 at 09:56

1 Answers1

1

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