0 Replies Latest reply: Apr 4, 2014 1:49 PM by PavolAlcohol RSS

    Problem with focus after glasspane is hidden

    PavolAlcohol

      Hi all,

       

      I have one frame containing panel with 4 JTextField component. I set focus to second textfield and show glasspane. After some time(long operation was finished) I hide glasspane (setVisible(false)) but first textfield has focus instead of second one.

       

      Can somebody tell me how to simple achieve that second one will be focuced as before?

       

      I tried to implement focusGained and focusLost events in my glasspane to store last focused component (e.getCompossiteComponent) but i don't know if it's good idea.

       

      something like this:

      public void focusGained(FocusEvent e)

      {

           this.lastFocused  = e.getCompossiteComponent()

      }

       

      public void focusLost(FocusEvent e)

      {

           this.lastFocused.requestFocus()

      }

       

      My glasspane can be later extended with additional components (possible to gain focus also) and I don't know if such is enough or not.

       

      Does better way exist to focus corrent textfield on my panel?

       

      thanks