Class Skeleton

java.lang.Object
org.vaadin.addons.skeleton.Skeleton

public final class Skeleton extends Object
Shows skeleton placeholders over every child of a component while its data loads.

 // Simplest: show, then hide yourself
 Skeleton.show(profileCard);
 ...
 Skeleton.hide(profileCard);

 // Recommended: load in the background, fill the UI, hide automatically
 Skeleton.load(profileCard,
         () -> userService.fetchProfile(id),   // runs off the UI thread
         profile -> {                          // runs with the UI locked
             name.setText(profile.name());
             title.setText(profile.title());
         });
 
All methods except the loading task itself must be called while holding the UI lock (i.e. from a listener, a view constructor or ui.access).

load(com.vaadin.flow.component.Component, java.util.function.Supplier<T>, com.vaadin.flow.function.SerializableConsumer<T>) requires server push (@Push on the app shell). Without push the browser is not told when the background task finishes, so the skeleton stays visible until the next unrelated server round trip.

  • Method Details

    • show

      public static void show(com.vaadin.flow.component.Component container)
      Shows placeholders over all leaf components inside container.
    • show

      public static void show(com.vaadin.flow.component.Component container, SkeletonOptions options)
      Shows placeholders over container using the given options.
    • hide

      public static void hide(com.vaadin.flow.component.Component container)
      Removes the placeholders and reveals the real content. Safe to call twice.
    • isShowing

      public static boolean isShowing(com.vaadin.flow.component.Component container)
    • markAsLeaf

      public static void markAsLeaf(com.vaadin.flow.component.Component component)
      Treats this component as a single placeholder block instead of descending into its children (useful for custom composite components).
    • exclude

      public static void exclude(com.vaadin.flow.component.Component component)
      Leaves this component (and everything inside it) visible and uncovered.
    • setDefaultExecutor

      public static void setDefaultExecutor(Executor executor)
    • load

      public static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess)
      Shows the skeleton, runs task in the background, then hands the result to onSuccess with the UI locked and hides the skeleton. Requires @Push.
    • load

      public static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess, com.vaadin.flow.function.SerializableConsumer<Throwable> onError)
    • load

      public static <T> CompletableFuture<T> load(com.vaadin.flow.component.Component container, SkeletonOptions options, Supplier<T> task, com.vaadin.flow.function.SerializableConsumer<T> onSuccess, com.vaadin.flow.function.SerializableConsumer<Throwable> onError, Executor executor)
      Full version of load.
      Parameters:
      onError - called with the UI locked if task throws; may be null, in which case the error is logged. The skeleton is hidden either way.
      executor - where task runs