Class EmptyState

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class EmptyState extends Container

An empty state (also called a zero state, blank slate or "no results" view): an icon, a title, a line of explanation and an optional action, centred where a list or a screen would otherwise be blank.

Show one when loading finished with nothing to show, or failed:

Form form = new Form("Orders", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));
form.add(BorderLayout.CENTER, new EmptyState(FontImage.MATERIAL_INBOX,
        "No orders yet", "Orders you place show up here."));
form.show();

// or, after an error, offer a retry:
// new EmptyState(FontImage.MATERIAL_CLOUD_OFF, "Can't load orders",
//         "Check your connection and try again.")
//         .setAction("Retry", e -> reload());

It is the counterpart of Skeleton, which fills the same place while the content is still loading.

UIIDs: EmptyState for the container, EmptyStateIcon, EmptyStateTitle, EmptyStateText and EmptyStateButton. Unstyled, they fall back to the theme's Label, SpanLabel and Button looks.

  • Constructor Details

    • EmptyState

      public EmptyState(char materialIcon, String title, String text)

      An empty state with a material icon, a title and an explanation.

      Parameters
      • materialIcon: a FontImage material icon constant, or 0 for none

      • title: the title, or null

      • text: the explanation, or null

  • Method Details

    • initUnselectedStyle

      protected void initUnselectedStyle(Style unselectedStyle)
      Description copied from class: Component

      Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

      Parameters
      • unselectedStyle: The unselected style.
      Overrides:
      initUnselectedStyle in class Component
    • setIcon

      public final EmptyState setIcon(char materialIcon)

      Sets the icon.

      Parameters
      • materialIcon: a FontImage material icon constant, or 0 for none
      Returns

      this, for chaining

    • setTitle

      public final EmptyState setTitle(String title)

      Sets the title.

      Parameters
      • title: the title, or null for none
      Returns

      this, for chaining

    • setText

      public final EmptyState setText(String text)

      Sets the explanation.

      Parameters
      • text: the explanation, or null for none
      Returns

      this, for chaining

    • setAction

      public EmptyState setAction(String label, ActionListener listener)

      Adds a button under the explanation, such as "Retry" or "Add an item". Calling it again replaces the label and the listener.

      Parameters
      • label: the button's text

      • listener: what the button does

      Returns

      this, for chaining

    • getActionButton

      public Button getActionButton()

      The action button, hidden until #setAction(String, ActionListener).

      Returns

      the button