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

public class Chip

  1. Object
  2. Component
  3. Container
  4. Chip

ImplementsAnimation, Editable, Iterable<Component>, StyleListener

A small rounded label for a tag, a filter or a choice: Material’s input, filter and choice chips.

Selectable, removable and plain chips

// filter chips: tap to toggle
Container filters = FlowLayout.encloseIn(
        new Chip("Vegan").setSelectable(true),
        new Chip("Gluten free").setSelectable(true),
        new Chip("Under 30 min").setSelectable(true).setSelected(true));

// an input chip that can be removed
Chip tag = new Chip("design").setRemovable(true);
tag.addRemoveListener(e -> tag.remove());

A selectable chip toggles on tap and shows a check mark while selected. A removable chip shows a close button, which fires the remove listeners and leaves removing the chip to them. Every tap fires the action listeners. ChipInput is a text field that turns what the user types into chips.

UIIDs: Chip and ChipSelected for the pill, ChipText for its text and ChipRemove for the close button. Unstyled, a chip is a rounded pill in the theme’s Slider track colour, and a selected one in the accent colour.

Constructors

public Chip(String text)A chip showing text.

Methods

public String getText()The chip’s text.
public Chip setText(String t)Sets the chip’s text.
public Button getTextLabel()The button holding the text, for an icon or a custom look.
public boolean isSelectable()Whether a tap toggles the chip.
public Chip setSelectable(boolean selectable)Makes a tap toggle the chip.
public boolean isSelected()Whether the chip is selected.
public Chip setSelected(boolean selected)Selects or deselects the chip.
public boolean isRemovable()Whether the chip shows a close button.
public Chip setRemovable(boolean removable)Shows or hides the close button.
public Button getRemoveButton()The close icon.
public void addActionListener(ActionListener l)Adds a listener called on every tap.
public void removeActionListener(ActionListener l)Removes a tap listener.
public void addRemoveListener(ActionListener l)Adds a listener called when the close button is tapped.
public void removeRemoveListener(ActionListener l)Removes a close listener.
public void pressed()Taps the chip as a user would: toggles it when selectable, then fires the action listeners.
public void requestRemove()Fires the remove listeners as the close button would.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, 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, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, 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, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, 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, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, deinitialize, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, 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, 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

Chip

public Chip(String text)
A chip showing text.

Parameters

text String
the chip’s text

Method details

getText

public String getText()
The chip’s text.

Returns

the text

setText

public Chip setText(String t)
Sets the chip’s text.

Parameters

t String
the text

Returns

this, for chaining

getTextLabel

public Button getTextLabel()
The button holding the text, for an icon or a custom look. It is the chip’s lead component, so it receives every tap on the chip.

Returns

the text button

isSelectable

public boolean isSelectable()
Whether a tap toggles the chip.

Returns

true for a filter or choice chip

setSelectable

public Chip setSelectable(boolean selectable)
Makes a tap toggle the chip.

Parameters

selectable boolean
true for a filter or choice chip

Returns

this, for chaining

isSelected

public boolean isSelected()
Whether the chip is selected.

Returns

the selection state

setSelected

public Chip setSelected(boolean selected)
Selects or deselects the chip.

Parameters

selected boolean
the selection state

Returns

this, for chaining

isRemovable

public boolean isRemovable()
Whether the chip shows a close button.

Returns

true for an input chip

setRemovable

public Chip setRemovable(boolean removable)
Shows or hides the close button.

Parameters

removable boolean
true for an input chip

Returns

this, for chaining

getRemoveButton

public Button getRemoveButton()
The close icon. It shows the icon only: taps reach the chip’s text button, which removes when the tap lands on this.

Returns

the close icon

addActionListener

public void addActionListener(ActionListener l)
Adds a listener called on every tap.

Parameters

l ActionListener
the listener

removeActionListener

public void removeActionListener(ActionListener l)
Removes a tap listener.

Parameters

l ActionListener
the listener

addRemoveListener

public void addRemoveListener(ActionListener l)
Adds a listener called when the close button is tapped.

Parameters

l ActionListener
the listener, which usually removes the chip

removeRemoveListener

public void removeRemoveListener(ActionListener l)
Removes a close listener.

Parameters

l ActionListener
the listener

pressed

public void pressed()
Taps the chip as a user would: toggles it when selectable, then fires the action listeners.

requestRemove

public void requestRemove()
Fires the remove listeners as the close button would.