public class Accordion
ImplementsAnimation, Editable, Iterable<Component>, StyleListener
The Accordion ui pattern is a vertically stacked list of items.
Each item can be opened/closed to reveal more content similarly to a com.codename1.ui.tree.Tree
however unlike the com.codename1.ui.tree.Tree the Accordion is designed to include
containers or arbitrary components rather than model based data.
This makes the Accordion more convenient as a tool for folding/collapsing UI elements known in advance
whereas a com.codename1.ui.tree.Tree makes more sense as a tool to map data e.g. filesystem
structure, XML hierarchy etc.
Note that the Accordion like many composite components in Codename One is scrollable by default
which means you should use it within a non-scrollable hierarchy. If you wish to add it into a scrollable
com.codename1.ui.Container you should disable it’s default scrollability using setScrollable(false).
Example Usage
Form f = new Form("Accordion", new BorderLayout());
Accordion accr = new Accordion();
accr.addContent("Item1", new SpanLabel("The quick brown fox jumps over the lazy dog\n"
+ "The quick brown fox jumps over the lazy dog"));
accr.addContent("Item2", new SpanLabel("The quick brown fox jumps over the lazy dog\n"
+ "The quick brown fox jumps over the lazy dog\n "
+ "The quick brown fox jumps over the lazy dog\n "
+ "The quick brown fox jumps over the lazy dog\n "
+ ""));
accr.addContent("Item3", BoxLayout.encloseY(new Label("Label"), new TextField(), new Button("Button"), new CheckBox("CheckBox")));
f.add(BorderLayout.CENTER, accr);
f.show();
Screenshots
Constructors
public Accordion() | Empty Constructor |
public Accordion(Image openIcon, Image closeIcon) | Create an accordion with open and close icons set |
public Accordion(char openIcon, char closeIcon) | Create an accordion with open and close icons set |
public Accordion(char openIcon, char closeIcon, String openCloseUIID) | Create an accordion with open and close icons set |
Methods
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 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, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, 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
Accordion
public Accordion()Accordion
public Accordion(Image openIcon, Image closeIcon)Parameters
openIconImage- the open icon of the accordion
closeIconImage- the close icon of the accordion
Accordion
public Accordion(char openIcon, char closeIcon)Parameters
openIconchar- the open icon of the accordion
closeIconchar- the close icon of the accordion
Accordion
public Accordion(char openIcon, char closeIcon, String openCloseUIID)Parameters
openIconchar- the open icon of the accordion
closeIconchar- the close icon of the accordion
openCloseUIIDString- the uiid of the open and close icons
Method details
addContent
public void addContent(String header, Component body)Parameters
headerString- the item title
bodyComponent- the item Component to hide/show
setHeader
public void setHeader(String header, Component body)Parameters
headerString- the new title for the content
bodyComponent- the content that was already added with a different header using addContent
setHeader
public void setHeader(Component header, Component body)Parameters
headerComponent- the new title for the content
bodyComponent- the content that was already added with a different header using addContent
removeContent
public void removeContent(Component body)Parameters
bodyComponent- the body previously added with
com.codename1.ui.Component)or
addContent
public void addContent(Component header, Component body)Parameters
headerComponent- the item title Component
bodyComponent- the item Component to hide/show
setHeaderUIID
public void setHeaderUIID(Component body, String uiid)Parameters
bodyComponent- the component within the accordion
uiidString- the uiid for the header
getCurrentlyExpanded
public Component getCurrentlyExpanded()Returns
expand
public void expand(Component body)Parameters
bodyComponent- the body component of the accordion to expand
collapse
public void collapse(Component body)Parameters
bodyComponent- the body component of the accordion to close
setCloseIcon
public void setCloseIcon(Image closeIcon)Parameters
closeIconImage- the close icon
setOpenIcon
public void setOpenIcon(Image openIcon)Parameters
openIconImage- the open icon
setCloseIcon
public void setCloseIcon(char closeIcon)Parameters
closeIconchar- the close icon (e.g.
FontImage.MATERIAL_KEYBOARD_ARROW_DOWN)
setOpenIcon
public void setOpenIcon(char openIcon)Parameters
openIconchar- the open icon (e.g.
FontImage.MATERIAL_KEYBOARD_ARROW_RIGHT)
setCloseIcon
public void setCloseIcon(char closeIcon, float size)Parameters
closeIconchar- the close icon (e.g.
FontImage.MATERIAL_KEYBOARD_ARROW_DOWN) sizefloat- the size in millimeters for the arrow
setOpenIcon
public void setOpenIcon(char openIcon, float size)Parameters
openIconchar- the open icon (e.g.
FontImage.MATERIAL_KEYBOARD_ARROW_RIGHT) sizefloat- the size in millimeters for the arrow
setCloseIcon
public void setCloseIcon(char closeIcon, String uiid)Parameters
closeIconchar- the close icon (e.g.
FontImage.MATERIAL_KEYBOARD_ARROW_DOWN) uiidString- to custom icon from res file
setOpenIcon
public void setOpenIcon(char openIcon, String uiid)Parameters
openIconchar- the open icon (e.g.
FontImage.MATERIAL_KEYBOARD_ARROW_RIGHT) uiidString- to custom icon from res file
setAutoClose
public void setAutoClose(boolean autoClose)Parameters
autoCloseboolean- determines if more then 1 item can be opened on screen
addOnClickItemListener
public void addOnClickItemListener(ActionListener a)Parameters
aActionListener- ActionListener to implement the method
removeOnClickItemListener
public void removeOnClickItemListener(ActionListener a)Parameters
aActionListener- ActionListener to implement the method
getBackgroundItemUIID
public String getBackgroundItemUIID()Returns
setBackgroundItemUIID
public void setBackgroundItemUIID(String uiidBackGroundItem)Parameters
uiidBackGroundItemString- to custom the background in the accordion component
getHeaderUIID
public String getHeaderUIID()Returns
setHeaderUIID
public void setHeaderUIID(String uiidHeader)Parameters
uiidHeaderString- to custom the header in the accordion component
getOpenCloseIconUIID
public String getOpenCloseIconUIID()Returns
setOpenCloseIconUIID
public void setOpenCloseIconUIID(String uiidOpenCloseIcon)Parameters
uiidOpenCloseIconString- to custom the background of the Open/Close icon