I am learning Java and Swing right now and am trying to develop simple programs for educational purposes.
So here is the question.
I have gridlayout and fields in my frame with default text
accNumberField = new JTextField("0", 10); accNumberField.addFocusListener(new FocusListener() { int focusCounter = 0; @Override public void focusGained(FocusEvent arg0) {
What I want is that when the user first clicks on the field, the default text disappears. So I add a focus listener and use accNumberField.setText (""); in focusGained method.
But the problem is that for the first field by default in my frame, the focus becomes right during the creation of the frame. And the default text disappears from the very beginning. I used a counter, as you can see. But this is not what I wanted.
I want no field to get focus during creation, and each field can get focus from the moment the user clicks on one of them.
Sorry if I wrote something wrong. English is not my native language.
source share