Class Overlay


public class Overlay extends StyledElement<Overlay>
A full-screen overlay container for modals, dialogs, and lightboxes.

Overlay creates a layer that covers its parent (or the viewport when fixed) and centers its content. It's commonly used for modal dialogs, loading screens, image lightboxes, and confirmation dialogs.

Features:

  • Fixed or absolute positioning
  • Configurable backdrop color and opacity
  • Content centering by default
  • Z-index control for stacking

Usage:


 // Simple modal overlay
 Overlay modal = new Overlay();
 modal.addElement(dialogBox);

 // Loading overlay with semi-transparent backdrop
 Overlay loading = new Overlay();
 loading.setBackdrop("rgba(0, 0, 0, 0.7)");
 loading.addElement(spinner);

 // Lightbox for images
 Overlay lightbox = new Overlay();
 lightbox.setBackdrop("rgba(0, 0, 0, 0.9)");
 lightbox.addElement(fullSizeImage);

 // Overlay within a container (not viewport)
 Overlay contained = Overlay.absolute();
 contained.addElement(tooltip);
 container.addElement(contained);
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Overlay

      public Overlay()
      Constructs a fixed overlay that covers the entire viewport.
  • Method Details

    • absolute

      public static Overlay absolute()
      Creates an absolute-positioned overlay within its parent container.

      The parent container should have position: relative for this to work correctly.

      Returns:
      a new absolute-positioned Overlay
    • setBackdrop

      public Overlay setBackdrop(String color)
      Sets the backdrop color.
      Parameters:
      color - the backdrop color (e.g., "rgba(0,0,0,0.5)", "#000", "transparent")
      Returns:
      this Overlay for method chaining
    • setBackdropOpacity

      public Overlay setBackdropOpacity(double opacity)
      Sets the backdrop opacity using a semi-transparent black.
      Parameters:
      opacity - the opacity value from 0.0 (transparent) to 1.0 (opaque)
      Returns:
      this Overlay for method chaining
    • setLightBackdrop

      public Overlay setLightBackdrop(double opacity)
      Sets a white semi-transparent backdrop.
      Parameters:
      opacity - the opacity value from 0.0 (transparent) to 1.0 (opaque)
      Returns:
      this Overlay for method chaining
    • noBackdrop

      public Overlay noBackdrop()
      Removes the backdrop (makes it transparent).
      Returns:
      this Overlay for method chaining
    • setZIndex

      public Overlay setZIndex(int zIndex)
      Sets the z-index for stacking order.
      Overrides:
      setZIndex in class StyledElement<Overlay>
      Parameters:
      zIndex - the z-index value
      Returns:
      this Overlay for method chaining
    • setBackdropBlur

      public Overlay setBackdropBlur(int blurPx)
      Adds blur effect to the backdrop.

      This creates a frosted glass effect by blurring the content behind the overlay. Note: This uses backdrop-filter which may not be supported in all browsers.

      Parameters:
      blurPx - the blur amount in pixels
      Returns:
      this Overlay for method chaining
    • alignTop

      public Overlay alignTop()
      Aligns content to the top of the overlay.
      Returns:
      this Overlay for method chaining
    • alignBottom

      public Overlay alignBottom()
      Aligns content to the bottom of the overlay.
      Returns:
      this Overlay for method chaining
    • alignLeft

      public Overlay alignLeft()
      Aligns content to the left of the overlay.
      Returns:
      this Overlay for method chaining
    • alignRight

      public Overlay alignRight()
      Aligns content to the right of the overlay.
      Returns:
      this Overlay for method chaining
    • withPadding

      public Overlay withPadding(String padding)
      Adds padding around the overlay content.
      Parameters:
      padding - the padding value (e.g., "1rem", "20px")
      Returns:
      this Overlay for method chaining
    • withPadding

      public Overlay withPadding(int padding)
      Adds padding around the overlay content in pixels.
      Parameters:
      padding - the padding in pixels
      Returns:
      this Overlay for method chaining