Class Spinner


public class Spinner extends Div<Spinner>
A CSS-only spinning loading indicator.

Renders a circular spinner using a bordered div with a CSS rotation animation. The spinner is centered within its container by default. All visual properties (size, colors, thickness, speed) are configurable via fluent setters.

Usage:


 // Default spinner
 panel.addElement(new Spinner());

 // Customized spinner
 panel.addElement(new Spinner()
     .setSize(48)
     .setColor("#dc2626")
     .setThickness(4)
     .setSpeed(0.6f));
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
  • Constructor Details

    • Spinner

      public Spinner()
      Constructs a Spinner with default settings.
  • Method Details

    • initialize

      protected void initialize()
      Description copied from class: Element
      Hook method called during element initialization.

      Override this method to set up the element's structure by adding child elements. This is called before Element.create() and only once during the element's lifecycle.

      Overrides:
      initialize in class StyledElement<Spinner>
    • setSize

      public Spinner setSize(int size)
      Sets the diameter of the spinner in pixels.
      Parameters:
      size - The diameter in pixels.
      Returns:
      This Spinner for method chaining.
    • getSize

      public int getSize()
      Returns the diameter of the spinner in pixels.
      Returns:
      The diameter in pixels.
    • setColor

      public Spinner setColor(String color)
      Sets the color of the spinning arc.
      Overrides:
      setColor in class StyledElement<Spinner>
      Parameters:
      color - A CSS color value (e.g., "#3b82f6", "rgb(59,130,246)").
      Returns:
      This Spinner for method chaining.
    • getColor

      public String getColor()
      Returns the color of the spinning arc.
      Returns:
      The CSS color value.
    • setTrackColor

      public Spinner setTrackColor(String trackColor)
      Sets the color of the background track circle.
      Parameters:
      trackColor - A CSS color value (e.g., "#e2e8f0").
      Returns:
      This Spinner for method chaining.
    • getTrackColor

      public String getTrackColor()
      Returns the color of the background track circle.
      Returns:
      The CSS color value.
    • setThickness

      public Spinner setThickness(int thickness)
      Sets the border thickness of the spinner ring in pixels.
      Parameters:
      thickness - The thickness in pixels.
      Returns:
      This Spinner for method chaining.
    • getThickness

      public int getThickness()
      Returns the border thickness of the spinner ring in pixels.
      Returns:
      The thickness in pixels.
    • setSpeed

      public Spinner setSpeed(float speed)
      Sets the animation speed in seconds per full rotation.
      Parameters:
      speed - The duration in seconds (e.g., 0.8f for a fast spin, 2.0f for a slow spin).
      Returns:
      This Spinner for method chaining.
    • getSpeed

      public float getSpeed()
      Returns the animation speed in seconds per full rotation.
      Returns:
      The duration in seconds.