Class FocusInEvent


public class FocusInEvent extends FocusEvent
Event fired when an HTML element receives keyboard focus.

This event is triggered when a user focuses on an interactive element such as a text input field, button, or link, either by clicking on it or navigating to it via keyboard (typically using the Tab key). Focus-in events are essential for implementing field validation, highlighting active controls, and managing user interaction flow.

Features:

  • Indicates when an element gains keyboard focus
  • Provides access to the focused element through getSource()
  • Dispatches to FocusListener implementations
  • Supports focus-based UI feedback and validation

Usage: Handle this event through a FocusListener to respond when elements receive focus. Common use cases include highlighting the active field, displaying help text, or preparing validation logic.


 public class FormFieldHandler implements FocusListener {
     @Override
     public void onEvent(FocusInEvent event) {
         Element field = event.getSource();
         field.addStyleClass("focused");
         // Show field-specific help text
         showHelpText(field.getId());
     }

     @Override
     public void onEvent(FocusOutEvent event) {
         // Handle focus out
     }
 }
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • FocusInEvent

      public FocusInEvent()
  • Method Details

    • dispatchTo

      public void dispatchTo(FocusListener listener)
      Dispatches this event to the specified listener.

      This method implements the visitor pattern to deliver the event to the appropriate handler method on the FocusListener. It calls the listener's onEvent(FocusInEvent) method.

      Specified by:
      dispatchTo in class Event<FocusListener>
      Parameters:
      listener - the FocusListener that will handle this event