Class RequestFocusListener

java.lang.Object
com.everdro1d.libs.swing.RequestFocusListener
All Implemented Interfaces:
EventListener, AncestorListener

public class RequestFocusListener extends Object implements 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.

  • Constructor Details

    • RequestFocusListener

      public RequestFocusListener()
      Convenience constructor. The listener is only used once, then it is removed from the component.

      Example:

      button1.addAncestorListener(new RequestFocusListener());
    • RequestFocusListener

      public RequestFocusListener(boolean removeListener)
      Constructor that controls whether this listen can be used once or multiple times.
      Parameters:
      removeListener - when true this listener is only invoked once otherwise it can be invoked multiple times.
  • Method Details