Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class Skeleton

  1. Object
  2. Component
  3. CommonProgressAnimations.ProgressAnimation
  4. Skeleton

ImplementsAnimation, Editable, StyleListener

A skeleton screen placeholder (also called a shimmer loader, content placeholder or ghost element): the grey outline of content that is still loading, with a light band sweeping across it.

Show one where content will land, so the screen says “loading” without a spinner and does not jump when the content arrives:

Form form = new Form("Orders", new BorderLayout());
Container list = new Container(BoxLayout.y());
list.add(Skeleton.rows(4));
form.add(BorderLayout.CENTER, list);
form.show();
// Stands in for a network call that answers after 2 seconds.
UITimer.timer(2000, false, form, () -> {
    list.removeAll();
    for (String order : new String[] {"Order #101", "Order #102"}) {
        list.add(new MultiButton(order));
    }
    list.animateLayout(200);
});

Or mask a component that already exists until its data is ready:

Form form = new Form("Profile", BoxLayout.y());
SpanLabel bio = new SpanLabel();
form.add(bio);
form.show();
Skeleton.show(bio, Skeleton.text(3));
UITimer.timer(2000, false, form, () -> {
    bio.setText("Builds mobile apps in Java.");
    Skeleton.hide(bio, CommonTransitions.createFade(200));
});

The shapes are drawn in the foreground colour of the Skeleton UIID. A theme that does not style that UIID gets the theme’s text colour at a low opacity, which suits light and dark themes alike. Restyle the UIID, or pass your own with setUIID, to change the colour, padding or margin. The shimmer runs only while the placeholder is on screen; turn it off with #shimmer(boolean).

Skeleton is a CommonProgressAnimations.ProgressAnimation, so it also works with CommonProgressAnimations.ProgressAnimation#markComponentLoading.

See also InfiniteProgress for a blocking spinner and EmptyState for what to show when loading finished with nothing to show.

Constructors

public Skeleton()A placeholder block that fills whatever size it is given.

Methods

protected void initUnselectedStyle(Style unselectedStyle)Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.
public static Skeleton rows(int rows)The outline of a list: per row, a round icon, a title, a shorter second line and a value at the far end.
public static Skeleton text(int lines)Lines of text, the last one shorter, as a paragraph would end.
public static Skeleton circle(float diameterMM)A circle, for an avatar or an icon.
public static Skeleton rect(float widthMM, float heightMM)A rounded rectangle, for an image, a button or a chart.
public static Skeleton card()A card: an image across the top, then a title and two lines of text.
public Skeleton shimmer(boolean shimmer)Turns the moving shimmer band on or off.
public Skeleton uiid(String uiid)Sets the UIID, for chaining: Skeleton.rows(5).uiid("MySkeleton").
public boolean isShimmer()Whether the shimmer band is on.
public static Skeleton show(Component cmp)Replaces a component in its parent with a block placeholder of the same preferred size until #hide(Component) is called.
public static Skeleton show(Component cmp, Skeleton placeholder)Replaces a component in its parent with the given placeholder until #hide(Component) is called, for instance Skeleton.text(3) in place of a SpanLabel.
public static void hide(Component cmp)Puts a component masked by #show(Component) back in its place.
public static void hide(Component cmp, Transition t)Puts a component masked by #show(Component) back in its place with a transition, such as a fade.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public void paint(Graphics g)This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyPressed, keyReleased, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerPressed, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

Skeleton

public Skeleton()
A placeholder block that fills whatever size it is given. This is the shape #show(Component) uses to mask a component.

Method details

initUnselectedStyle

protected void initUnselectedStyle(Style unselectedStyle)
Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

Parameters

unselectedStyle Style
The unselected style.

rows

public static Skeleton rows(int rows)
The outline of a list: per row, a round icon, a title, a shorter second line and a value at the far end.

Parameters

rows int
how many rows to outline

Returns

the placeholder

text

public static Skeleton text(int lines)
Lines of text, the last one shorter, as a paragraph would end.

Parameters

lines int
how many lines

Returns

the placeholder

circle

public static Skeleton circle(float diameterMM)
A circle, for an avatar or an icon.

Parameters

diameterMM float
the diameter in millimetres

Returns

the placeholder

rect

public static Skeleton rect(float widthMM, float heightMM)
A rounded rectangle, for an image, a button or a chart.

Parameters

widthMM float
the width in millimetres; 0 or less takes the full width
heightMM float
the height in millimetres

Returns

the placeholder

card

public static Skeleton card()
A card: an image across the top, then a title and two lines of text.

Returns

the placeholder

shimmer

public Skeleton shimmer(boolean shimmer)
Turns the moving shimmer band on or off. It is on by default; off, the placeholder is a still outline.

Parameters

shimmer boolean
true for the moving band

Returns

this, for chaining

uiid

public Skeleton uiid(String uiid)
Sets the UIID, for chaining: Skeleton.rows(5).uiid("MySkeleton").

Parameters

uiid String
the style whose foreground the shapes are drawn in

Returns

this, for chaining

isShimmer

public boolean isShimmer()
Whether the shimmer band is on.

Returns

true if the band moves across the placeholder

show

public static Skeleton show(Component cmp)
Replaces a component in its parent with a block placeholder of the same preferred size until #hide(Component) is called. Calling it again while the component is masked returns the placeholder already showing.

Parameters

cmp Component
a component that has a parent

Returns

the placeholder that took its place

show

public static Skeleton show(Component cmp, Skeleton placeholder)
Replaces a component in its parent with the given placeholder until #hide(Component) is called, for instance Skeleton.text(3) in place of a SpanLabel.

Parameters

cmp Component
a component that has a parent
placeholder Skeleton
what to show in its place

Returns

the placeholder showing; when the component was already masked by a Skeleton, that one; null when another kind of progress animation already masks it

hide

public static void hide(Component cmp)
Puts a component masked by #show(Component) back in its place. Does nothing if it is not masked.

Parameters

cmp Component
the component to restore

hide

public static void hide(Component cmp, Transition t)
Puts a component masked by #show(Component) back in its place with a transition, such as a fade. Does nothing if it is not masked.

Parameters

cmp Component
the component to restore
t Transition
the transition, or null to swap at once

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

paint

public void paint(Graphics g)
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Parameters

g Graphics
the component graphics