Class Accordion
- All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>
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
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsConstructorDescriptionEmpty ConstructorAccordion(char openIcon, char closeIcon) Create an accordion with open and close icons setCreate an accordion with open and close icons setCreate an accordion with open and close icons set -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContent(Component header, Component body) Add an item to the Accordion ContainervoidaddContent(String header, Component body) Add an item to the Accordion ContainervoidTo listen item click in accordion componentvoidCloses the accordion with the given "body"voidExpands the accordion with the given "body"Default UIID for the content item within the accordionReturns the body component of the currently expanded accordion element or null if none is expandedUIID for the header componentUIID for the arrow icon for expanding/collapsingvoidremoveContent(Component body) Removes the content from the accordionvoidTo remove item click in accordion componentvoidsetAutoClose(boolean autoClose) Sets the auto close flag, if this flag is true clicking on an item to open an item will automatically close the previous opened item.voidsetBackgroundItemUIID(String uiidBackGroundItem) Default UIID for the content item within the accordionvoidsetCloseIcon(char closeIcon) Sets the closed icon using material imagevoidsetCloseIcon(char closeIcon, float size) Sets the closed icon using material imagevoidsetCloseIcon(char closeIcon, String uiid) Sets the closed icon using material image with a custom uiidvoidsetCloseIcon(Image closeIcon) Sets the closed iconvoidReplaces the title for content that was already added.voidReplaces the title for content that was already added.voidsetHeaderUIID(Component body, String uiid) Sets the header UIID for the given accordion uiidvoidsetHeaderUIID(String uiidHeader) UIID for the header componentvoidsetOpenCloseIconUIID(String uiidOpenCloseIcon) UIID for the arrow icon for expanding/collapsingvoidsetOpenIcon(char openIcon) Sets the open icon using material imagevoidsetOpenIcon(char openIcon, float size) Sets the open icon using material imagevoidsetOpenIcon(char openIcon, String uiid) Sets the open icon using material image with a custom uiidvoidsetOpenIcon(Image openIcon) Sets the open iconMethods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
Accordion
public Accordion()Empty Constructor -
Accordion
-
Accordion
public Accordion(char openIcon, char closeIcon) Create an accordion with open and close icons set
Parameters
-
openIcon: the open icon of the accordion -
closeIcon: the close icon of the accordion
-
-
Accordion
Create an accordion with open and close icons set
Parameters
-
openIcon: the open icon of the accordion -
closeIcon: the close icon of the accordion -
openCloseUIID: the uiid of the open and close icons
-
-
-
Method Details
-
addContent
-
setHeader
-
setHeader
-
removeContent
Removes the content from the accordion
Parameters
body: the body previously added withcom.codename1.ui.Component)or
-
addContent
-
setHeaderUIID
-
getCurrentlyExpanded
Returns the body component of the currently expanded accordion element or null if none is expanded
Returns
a component
-
expand
Expands the accordion with the given "body"
Parameters
body: the body component of the accordion to expand
-
collapse
Closes the accordion with the given "body"
Parameters
body: the body component of the accordion to close
-
setCloseIcon
Sets the closed icon
Parameters
closeIcon: the close icon
-
setOpenIcon
Sets the open icon
Parameters
openIcon: the open icon
-
setCloseIcon
public void setCloseIcon(char closeIcon) Sets the closed icon using material image
Parameters
closeIcon: the close icon (e.g.FontImage.MATERIAL_KEYBOARD_ARROW_DOWN)
-
setOpenIcon
public void setOpenIcon(char openIcon) Sets the open icon using material image
Parameters
openIcon: the open icon (e.g.FontImage.MATERIAL_KEYBOARD_ARROW_RIGHT)
-
setCloseIcon
public void setCloseIcon(char closeIcon, float size) Sets the closed icon using material image
Parameters
-
closeIcon: the close icon (e.g.FontImage.MATERIAL_KEYBOARD_ARROW_DOWN) -
size: the size in millimeters for the arrow
-
-
setOpenIcon
public void setOpenIcon(char openIcon, float size) Sets the open icon using material image
Parameters
-
openIcon: the open icon (e.g.FontImage.MATERIAL_KEYBOARD_ARROW_RIGHT) -
size: the size in millimeters for the arrow
-
-
setCloseIcon
Sets the closed icon using material image with a custom uiid
Parameters
-
closeIcon: the close icon (e.g.FontImage.MATERIAL_KEYBOARD_ARROW_DOWN) -
uiid: to custom icon from res file
-
-
setOpenIcon
Sets the open icon using material image with a custom uiid
Parameters
-
openIcon: the open icon (e.g.FontImage.MATERIAL_KEYBOARD_ARROW_RIGHT) -
uiid: to custom icon from res file
-
-
setAutoClose
public void setAutoClose(boolean autoClose) Sets the auto close flag, if this flag is true clicking on an item to open an item will automatically close the previous opened item.
Parameters
autoClose: determines if more then 1 item can be opened on screen
-
addOnClickItemListener
To listen item click in accordion component
Parameters
a: ActionListener to implement the method
-
removeOnClickItemListener
To remove item click in accordion component
Parameters
a: ActionListener to implement the method
-
getBackgroundItemUIID
Default UIID for the content item within the accordion
Returns
the uiid
-
setBackgroundItemUIID
Default UIID for the content item within the accordion
Parameters
uiidBackGroundItem: to custom the background in the accordion component
-
getHeaderUIID
UIID for the header component -
setHeaderUIID
UIID for the header component
Parameters
uiidHeader: to custom the header in the accordion component
-
getOpenCloseIconUIID
UIID for the arrow icon for expanding/collapsing
Returns
the UIID
-
setOpenCloseIconUIID
UIID for the arrow icon for expanding/collapsing
Parameters
uiidOpenCloseIcon: to custom the background of the Open/Close icon
-