Class RequestFocusListener

  • All Implemented Interfaces:
    java.util.EventListener, javax.swing.event.AncestorListener

    public class RequestFocusListener
    extends java.lang.Object
    implements javax.swing.event.AncestorListener
    Convenience class to request focus on a component. When the component is added to a realized Window then component will request focus immediately, since the ancestorAdded event is fired immediately. When the component is added to a non realized Window, then the focus request will be made once the window is realized, since the ancestorAdded event will not be fired until then. Using the default constructor will cause the listener to be removed from the component once the AncestorEvent is generated. A second constructor allows you to specify a boolean value of false to prevent the AncestorListener from being removed when the event is generated. This will allow you to reuse the listener each time the event is generated.

    Source credit

    • Constructor Detail

      • RequestFocusListener

        public RequestFocusListener()
      • RequestFocusListener

        public RequestFocusListener​(boolean removeListener)
    • Method Detail

      • ancestorAdded

        public void ancestorAdded​(javax.swing.event.AncestorEvent e)
        Specified by:
        ancestorAdded in interface javax.swing.event.AncestorListener
      • ancestorMoved

        public void ancestorMoved​(javax.swing.event.AncestorEvent e)
        Specified by:
        ancestorMoved in interface javax.swing.event.AncestorListener
      • ancestorRemoved

        public void ancestorRemoved​(javax.swing.event.AncestorEvent e)
        Specified by:
        ancestorRemoved in interface javax.swing.event.AncestorListener