Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class 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
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From CommonProgressAnimations.ProgressAnimation
markComponentLoading, markComponentLoading, markComponentReady, markComponentReady, getProgressAnimation, deinitialize
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()#show(Component) uses to mask a component.Method details
initUnselectedStyle
protected void initUnselectedStyle(Style unselectedStyle)Parameters
unselectedStyleStyle- The unselected style.
rows
public static Skeleton rows(int rows)Parameters
rowsint- how many rows to outline
Returns
text
public static Skeleton text(int lines)Parameters
linesint- how many lines
Returns
circle
public static Skeleton circle(float diameterMM)Parameters
diameterMMfloat- the diameter in millimetres
Returns
rect
public static Skeleton rect(float widthMM, float heightMM)Parameters
widthMMfloat- the width in millimetres; 0 or less takes the full width
heightMMfloat- the height in millimetres
Returns
card
public static Skeleton card()Returns
shimmer
public Skeleton shimmer(boolean shimmer)Parameters
shimmerboolean- true for the moving band
Returns
uiid
public Skeleton uiid(String uiid)Skeleton.rows(5).uiid("MySkeleton").Parameters
uiidString- the style whose foreground the shapes are drawn in
Returns
isShimmer
public boolean isShimmer()Returns
show
public static Skeleton show(Component cmp)#hide(Component) is called. Calling it again while
the component is masked returns the placeholder already showing.Parameters
cmpComponent- a component that has a parent
Returns
show
public static Skeleton show(Component cmp, Skeleton placeholder)#hide(Component) is called, for instance Skeleton.text(3) in place of
a SpanLabel.Parameters
cmpComponent- a component that has a parent
placeholderSkeleton- what to show in its place
Returns
Skeleton, that one; null when another kind of progress animation
already masks ithide
public static void hide(Component cmp)#show(Component) back in its place. Does
nothing if it is not masked.Parameters
cmpComponent- the component to restore
hide
public static void hide(Component cmp, Transition t)#show(Component) back in its place with a
transition, such as a fade. Does nothing if it is not masked.Parameters
cmpComponent- the component to restore
tTransition- the transition, or null to swap at once
initComponent
protected void initComponent()animate
public boolean animate()com.codename1.ui.Display class.Returns
calcPreferredSize
protected Dimension calcPreferredSize()Returns
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics