Class LiveRegion


public class LiveRegion extends Div<LiveRegion>
A container that announces content changes to screen readers.

Live regions are used to notify screen reader users of dynamic content changes without requiring focus to move to the changed content. This is essential for:

  • Status messages (e.g., "File saved successfully")
  • Error notifications
  • Progress updates
  • Chat messages
  • Real-time data updates

Usage:


 // Create a polite live region for status messages
 LiveRegion status = new LiveRegion();
 body.addElement(status);

 // Later, announce a message
 status.announce("File saved successfully");

 // For urgent messages, use assertive mode
 LiveRegion alerts = new LiveRegion(AriaLive.ASSERTIVE);
 body.addElement(alerts);
 alerts.announce("Session will expire in 1 minute");
 

Politeness levels:

  • POLITE: Announced when user is idle. Use for most status messages.
  • ASSERTIVE: Announced immediately, interrupting the user. Use sparingly for critical messages only.
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • LiveRegion

      public LiveRegion()
      Creates a live region with polite politeness level.

      Polite live regions wait until the user is idle before announcing changes. This is appropriate for most status messages.

    • LiveRegion

      public LiveRegion(AriaLive politeness)
      Creates a live region with the specified politeness level.
      Parameters:
      politeness - POLITE waits for user idle, ASSERTIVE interrupts immediately.
  • Method Details

    • announce

      public void announce(String message)
      Announces a message to screen readers.

      The message is announced according to the live region's politeness level. This method clears the region first to ensure the new message is detected as a change by assistive technologies.

      Parameters:
      message - The message to announce.
    • clear

      public void clear()
      Clears the live region content.