Class List<T>
- All Implemented Interfaces:
Animation, Editable, ActionSource, StyleListener
A set of elements that is rendered using a com.codename1.ui.list.ListCellRenderer
and are extracted via the com.codename1.ui.list.ListModel, notice that
we strongly discourage usage of lists.
A list can represent many UI concepts ranging from a carousel to a "todo" checklist, this is made possible thanks to extensive use of Swing's style of MVC. Specifically a list component is relatively simple, it invokes the model in order to extract the displayed/selected information and shows it to the user by invoking the cell renderer.
The list class itself is completely decoupled from everything, thus it allows us to extract its content from any source (e.g. network, storage etc.) and display the information in any form (e.g. checkboxed elemenents, icons etc.).
Important
List is a pretty complex class to use so we generally recommend developers use
com.codename1.ui.Container,
com.codename1.components.InfiniteScrollAdapter or com.codename1.ui.InfiniteContainer
coupled with widgets such as com.codename1.components.MultiButton. Arranging those in a
com.codename1.ui.layouts.BoxLayout on the com.codename1.ui.layouts.BoxLayout#Y_AXIS
can produce the functionality of the List with better performance and far simpler code!
Another simpler alternative although not as attractive is the com.codename1.ui.list.MultiList class
that removes a lot of the com.codename1.ui.list.ListCellRenderer related complexities inherent
in building a list.
Sample Usage
The sample below uses the com.codename1.ui.list.GenericListCellRenderer class instead of the
com.codename1.ui.list.DefaultListCellRenderer. We generally recommend using the builtin classes
as the renderer is probably the greatest source of pitfalls in Lists.
public void showForm() {
com.codename1.ui.List list = new com.codename1.ui.List(createGenericListCellRendererModelData());
list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
Form hi = new Form("GenericListCellRenderer", new BorderLayout());
hi.add(BorderLayout.CENTER, list);
hi.show();
}
private Container createGenericRendererContainer() {
Label name = new Label();
name.setFocusable(true);
name.setName("Name");
Label surname = new Label();
surname.setFocusable(true);
surname.setName("Surname");
CheckBox selected = new CheckBox();
selected.setName("Selected");
selected.setFocusable(true);
Container c = BorderLayout.center(name).
add(BorderLayout.SOUTH, surname).
add(BorderLayout.WEST, selected);
c.setUIID("ListRenderer");
return c;
}
private Object[] createGenericListCellRendererModelData() {
Map[] data = new HashMap[5];
data[0] = new HashMap<>();
data[0].put("Name", "Shai");
data[0].put("Surname", "Almog");
data[0].put("Selected", Boolean.TRUE);
data[1] = new HashMap<>();
data[1].put("Name", "Chen");
data[1].put("Surname", "Fishbein");
data[1].put("Selected", Boolean.TRUE);
data[2] = new HashMap<>();
data[2].put("Name", "Ofir");
data[2].put("Surname", "Leitner");
data[3] = new HashMap<>();
data[3].put("Name", "Yaniv");
data[3].put("Surname", "Vakarat");
data[4] = new HashMap<>();
data[4].put("Name", "Meirav");
data[4].put("Surname", "Nachmanovitch");
return data;
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates the list selection is fixed into place at the center of the liststatic final intIndicates the list selection is fixed into place at the top of the list or at the left of the liststatic final intIndicates the list isn't fixed and that selection is movablestatic final intIndicates that the list is not fixed in place but cycles its elementsstatic final intIndicates the list selection will only reach the edge when there are no more elements in the list.static final intIndicates the list selection is fixed into place at the bottom of the list or at the right of the liststatic final intIndicates the list orientation is HORIZONTALstatic final intIndicates the list orientation is VERTICALFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAllows binding a listener to user selection actionsvoidAllows adding an element to a list if the underlying model supports this, notice that it is an optional operation and if the model does not support it (default list model does) then this operation may failed.voidInvoked to indicate interest in future selection eventsbooleananimate()Allows the animation to reduce "repaint" calls when it returns false.protected DimensionCalculates the preferred size based on component content.protected voidprotected voidTriggers the event to the listenersprotected voidWhen working in 3 softbutton mode "fire" key (center softbutton) is sent to this method in order to allow 3 button devices to work properly.This method allows extracting the action listeners from the current listintReturns the visual selection during a drag operation, otherwise equivalent to model.getSelectedIndexprotected intgetDragRegionStatus(int x, int y) Indicates if the section within the X/Y area is a "drag region" where we expect people to drag or press in which case we can instantly start dragging making perceived performance faster.intIndicates whether selection is fixable to place in which case all the elements in the list move and selection stays in place.protected intThis method should be implemented correctly by subclasses to make snap to grid functionality work as expected.protected intThis method should be implemented correctly by subclasses to make snap to grid functionality work as expected.getHint()Returns the hint textReturns the hint iconintReturns the gap between itemsThis method allows extracting the action listeners from the current listintIndicates the number of elements the list should check to determine the element sizes.intMaximum number of elements shown in a list, this member is used to calculate the list preferred size.intMinimum number of elements shown in a list, this member is used to calculate the list preferred size.getModel()Returns the model underlying the listintReturns the list orientationfinal ListCellRendererReturns the renderer which is used to draw list elementsSee set rendering prototypeintReturns the current selected offset in the listReturns the current selected item in the list or null for no selectionReturns the component bounds with absolute screen coordinates, for components that include an internal selection behavior and are not containers (currently only List) this method allows returning the position of the selection itself which is useful for things such as the popup dialog and similar UI's that need to reference the position of the selection externallyintReturns the gap to be left for the side scrollbar on the Y axis.protected RectangleReturns the component bounds for scrolling which might differ from the getBounds for large components e.g.protected voidThis method initializes the Component defaults constantsbooleanIndicates that the list should be treated as a list of commands, if the user "clicks" a command from the list its action performed method is invoked.static booleanDefault value for the fire on click behaviorstatic booleanIndicates whether the list should not paint the focus component if the list itself has no focus.booleanIndicates whether the list should not paint the focus component if the list itself has no focus.booleanEnable/disable list action on long pointer press eventbooleanIndicates that the background of a cell renderer might mutate between one entry and the next, it is recommended that this flag remains false for performance reasons.booleanIndicate whether pressing the number keys should trigger an actionbooleanIndicates whether the component should/could scroll on the X axisbooleanIndicates whether the component should/could scroll on the Y axisprotected booleanThis method allows a component to indicate that it is interested in an "implicit" select command to appear in the "fire" button when 3 softbuttons are defined in a device.protected booleanisTactileTouch(int x, int y) Elaborate components might not provide tactile feedback for all their areas (e.g. Lists) this method defaults to returning the value of isTactileTouchvoidkeyPressed(int keyCode) If this Component is focused, the key pressed event will call this methodvoidkeyReleased(int keyCode) If this Component is focused, the key released event will call this methodprotected voidlaidOut()This is a callback method to inform the Component when it's been laidout on the parent Containerprotected voidlistSelectionChanged(int oldSelected, int newSelected) Callback to allow subclasses to react to a selection change in the modelvoidlongPointerPress(int x, int y) If this Component is focused this method is invoked when the user presses and holds the pointer on the Componentprotected voidmodelChanged(int status, int index) Callback to allow subclasses to react to a change in the modelvoidThis 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.protected StringReturns a string representing the state of this component.voidpointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this methodvoidpointerHover(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display.voidpointerHoverReleased(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display.voidpointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this methodvoidpointerReleased(int x, int y) If this Component is focused, the pointer released event will call this methodvoidrefreshTheme(boolean merge) Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!voidAllows binding a listener to user selection actionsvoidInvoked to indicate no further interest in future selection eventsvoidscrollRectToVisible(Rectangle rect) Makes sure the selected index is visible if it is not in the current view rect the list will scroll so it fits withinvoidsetCommandList(boolean commandList) Indicates that the list should be treated as a list of commands, if the user "clicks" a command from the list its action performed method is invoked.static voidsetDefaultFireOnClick(boolean aDefaultFireOnClick) Default value for the fire on click behaviorstatic voidsetDefaultIgnoreFocusComponentWhenUnfocused(boolean aDefaultIgnoreFocusComponentWhenUnfocused) Indicates whether the list should not paint the focus component if the list itself has no focus.voidsetFireOnClick(boolean fireOnClick) This method determines if the List fires the action event when the pointer was clicked on one of the items, or only if the item was the selected item By default the value is true, this setting is only relevant for none fixed ListsvoidsetFixedSelection(int fixedSelection) Indicates whether selection is fixable to place in which case all the elements in the list move and selection stays in place.voidsetHandlesInput(boolean b) Prevents key events from being grabbed for focus traversal.voidSets the TextArea hint text, the hint text is displayed on the TextArea When there is no text in the TextAreavoidSets the TextArea hint text and Icon, the hint text and icon are displayed on the TextArea when there is no text in the TextAreavoidsetHintIcon(Image icon) Sets the TextArea hint icon, the hint is displayed on the TextArea When there is no text in the TextAreavoidsetIgnoreFocusComponentWhenUnfocused(boolean ignoreFocusComponentWhenUnfocused) Indicates whether the list should not paint the focus component if the list itself has no focus.voidsetInputOnFocus(boolean inputOnFocus) A list can start handling input implicitly upon gaining focus, this can make for a more intuitive UI when no other focus elements exist or when their use case is infrequent.voidsetItemGap(int itemGap) Set the gap between itemsvoidsetListCellRenderer(ListCellRenderer renderer) Sets the renderer which is used to draw list elementsvoidsetListSizeCalculationSampleCount(int listSizeCalculationSampleCount) Indicates the number of elements the list should check to determine the element sizes.voidsetLongPointerPressActionEnabled(boolean longPointerPressAction) Enable/disable list action on long pointer press eventvoidsetMaxElementHeight(int maxElementHeight) Maximum number of elements shown in a list, this member is used to calculate the list preferred size.voidsetMinElementHeight(int minElementHeight) Minimum number of elements shown in a list, this member is used to calculate the list preferred size.voidReplaces/sets the model underlying the listvoidsetMutableRendererBackgrounds(boolean mutableRendererBackgrounds) Indicates that the background of a cell renderer might mutate between one entry and the next, it is recommended that this flag remains false for performance reasons.voidsetNumericKeyActions(boolean numericKeyActions) Indicate whether pressing the number keys should trigger an actionvoidsetOrientation(int orientation) Sets the list orientation HORIZONTAL or VERTICALvoidsetPaintFocusBehindList(boolean paintFocusBehindList) This method determines if the animated focus is drawn on top of the List or behind the List when moving.final voidsetRenderer(ListCellRenderer renderer) Sets the renderer which is used to draw list elementsvoidsetRenderingPrototype(T renderingPrototype) The rendering prototype is optionally used in calculating the size of the List and is recommended for performance reasons.voidsetScrollToSelected(boolean scrollToSelected) This flag indicates to the List if the List should scroll to the selected element when it's been initialized.voidsetSelectedIndex(int index) Sets the current selected offset in the list, by default this implementation will scroll the list to the selection if the selection is outside of the screenvoidsetSelectedIndex(int index, boolean scrollToSelection) Sets the current selected offset in the listvoidsetSelectedItem(T item) Sets the current selected item in the listvoidsetShouldCalcPreferredSize(boolean shouldCalcPreferredSize) Indicates the values within the component have changed and preferred size should be recalculatedprotected booleanAllows subclasses to override the selection rendering for the component, specifically the spinner in some themesintsize()Returns the number of elements in the list, shorthand for getModel().getSize()Methods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, 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, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUIManager, getUnselectedStyle, 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, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, longKeyPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHoverPressed, pointerPressed, 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, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, 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, visibleBoundsContains
-
Field Details
-
FIXED_NONE
public static final int FIXED_NONEIndicates the list isn't fixed and that selection is movable- See Also:
-
FIXED_NONE_CYCLIC
public static final int FIXED_NONE_CYCLICIndicates that the list is not fixed in place but cycles its elements- See Also:
-
FIXED_NONE_ONE_ELEMENT_MARGIN_FROM_EDGE
public static final int FIXED_NONE_ONE_ELEMENT_MARGIN_FROM_EDGEIndicates the list selection will only reach the edge when there are no more elements in the list.- See Also:
-
FIXED_LEAD
public static final int FIXED_LEADIndicates the list selection is fixed into place at the top of the list or at the left of the list- See Also:
-
FIXED_TRAIL
public static final int FIXED_TRAILIndicates the list selection is fixed into place at the bottom of the list or at the right of the list- See Also:
-
FIXED_CENTER
public static final int FIXED_CENTERIndicates the list selection is fixed into place at the center of the list- See Also:
-
VERTICAL
public static final int VERTICALIndicates the list orientation is VERTICAL- See Also:
-
HORIZONTAL
public static final int HORIZONTALIndicates the list orientation is HORIZONTAL- See Also:
-
-
Constructor Details
-
List
Creates a new instance of List
Parameters
items: set of items placed into the list model
-
List
Creates a new instance of List
Parameters
items: set of items placed into the list model
-
List
public List()Creates a new instance of List with an empty default model -
List
Creates a new instance of List with the given model
Parameters
model: the model instance
-
-
Method Details
-
isDefaultIgnoreFocusComponentWhenUnfocused
public static boolean isDefaultIgnoreFocusComponentWhenUnfocused()Indicates whether the list should not paint the focus component if the list itself has no focus.
Returns
the defaultIgnoreFocusComponentWhenUnfocused
-
setDefaultIgnoreFocusComponentWhenUnfocused
public static void setDefaultIgnoreFocusComponentWhenUnfocused(boolean aDefaultIgnoreFocusComponentWhenUnfocused) Indicates whether the list should not paint the focus component if the list itself has no focus.
Parameters
aDefaultIgnoreFocusComponentWhenUnfocused: the defaultIgnoreFocusComponentWhenUnfocused to set
-
isDefaultFireOnClick
public static boolean isDefaultFireOnClick()Default value for the fire on click behavior
Returns
the defaultFireOnClick
-
setDefaultFireOnClick
public static void setDefaultFireOnClick(boolean aDefaultFireOnClick) Default value for the fire on click behavior
Parameters
aDefaultFireOnClick: the defaultFireOnClick to set
-
initLaf
-
laidOut
-
modelChanged
protected void modelChanged(int status, int index) Callback to allow subclasses to react to a change in the model
Parameters
-
status: the type data change; REMOVED, ADDED or CHANGED -
index: item index in a list model
-
-
listSelectionChanged
protected void listSelectionChanged(int oldSelected, int newSelected) Callback to allow subclasses to react to a selection change in the model
Parameters
-
oldSelected: the old selection value -
newSelected: the new selection value
-
-
getSideGap
public int getSideGap()Returns the gap to be left for the side scrollbar on the Y axis. This method is used by layout managers to determine the room they should leave for the scrollbar. (note: side scrollbar rather than left scrollbar is used for a future version that would support bidi).
Returns
the gap to be left for the side scrollbar on the Y axis
- Overrides:
getSideGapin classComponent
-
isScrollableY
public boolean isScrollableY()Indicates whether the component should/could scroll on the Y axis
Returns
whether the component is scrollable on the X axis
- Overrides:
isScrollableYin classComponent
-
isScrollableX
public boolean isScrollableX()Indicates whether the component should/could scroll on the X axis
Returns
whether the component is scrollable on the X axis
- Overrides:
isScrollableXin classComponent
-
getMaxElementHeight
public int getMaxElementHeight()Maximum number of elements shown in a list, this member is used to calculate the list preferred size. If the number of elements in the model is larger than this then this value is used in the calculations.
Returns
the maximum number of elements
-
setMaxElementHeight
public void setMaxElementHeight(int maxElementHeight) Maximum number of elements shown in a list, this member is used to calculate the list preferred size. If the number of elements in the model is larger than this then this value is used in the calculations.
Parameters
maxElementHeight: the maximum number of elements
-
getMinElementHeight
public int getMinElementHeight()Minimum number of elements shown in a list, this member is used to calculate the list preferred size. If the number of elements in the model is smaller than this then this value is used in the calculations.
Returns
the minimum number of elements
-
setMinElementHeight
public void setMinElementHeight(int minElementHeight) Minimum number of elements shown in a list, this member is used to calculate the list preferred size. If the number of elements in the model is smaller than this then this value is used in the calculations.
Parameters
minElementHeight: the minimum number of elements
-
size
public int size()Returns the number of elements in the list, shorthand for getModel().getSize()
Returns
the number of elements in the list
-
getCurrentSelected
public int getCurrentSelected()Returns the visual selection during a drag operation, otherwise equivalent to model.getSelectedIndex
Returns
visual selection
-
getSelectedIndex
public int getSelectedIndex()Returns the current selected offset in the list
Returns
the current selected offset in the list
-
setSelectedIndex
public void setSelectedIndex(int index) Sets the current selected offset in the list, by default this implementation will scroll the list to the selection if the selection is outside of the screen
Parameters
index: the current selected offset in the list
-
getVisibleBounds
Returns the component bounds for scrolling which might differ from the getBounds for large components e.g. list.
Returns
the component bounds
See also
-
#getX
-
#getY
-
#getVisibleBounds(com.codename1.ui.geom.Rectangle)
- Overrides:
getVisibleBoundsin classComponent
-
-
getDragRegionStatus
protected int getDragRegionStatus(int x, int y) Indicates if the section within the X/Y area is a "drag region" where we expect people to drag or press in which case we can instantly start dragging making perceived performance faster. This is invoked by the implementation code to optimize drag start behavior
Parameters
-
x: x location for the touch -
y: y location for the touch
Returns
one of the DRAG_REGION_* values
- Overrides:
getDragRegionStatusin classComponent
-
-
setSelectedIndex
public void setSelectedIndex(int index, boolean scrollToSelection) Sets the current selected offset in the list
Parameters
-
index: the current selected offset in the list -
scrollToSelection: @param scrollToSelection indicates whether scrolling to selection should occur if the selection is outside of view
-
-
getSelectedItem
Returns the current selected item in the list or null for no selection
Returns
the current selected item in the list
-
setSelectedItem
Sets the current selected item in the list
Parameters
item: the current selected item in the list
-
getModel
-
setModel
Replaces/sets the model underlying the list
Parameters
model: the new model underlying the list
-
setShouldCalcPreferredSize
public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize) Indicates the values within the component have changed and preferred size should be recalculated
Parameters
shouldCalcPreferredSize: @param shouldCalcPreferredSize indicate whether this component need to recalculate his preferred size
- Overrides:
setShouldCalcPreferredSizein classComponent
-
isNumericKeyActions
public boolean isNumericKeyActions()Indicate whether pressing the number keys should trigger an action
Returns
true if pressing the number keys should trigger an action
-
setNumericKeyActions
public void setNumericKeyActions(boolean numericKeyActions) Indicate whether pressing the number keys should trigger an action
Parameters
numericKeyActions: true to trigger an action on number keys
-
isCommandList
public boolean isCommandList()Indicates that the list should be treated as a list of commands, if the user "clicks" a command from the list its action performed method is invoked.
Returns
true if the list is treated as a command list
-
setCommandList
public void setCommandList(boolean commandList) Indicates that the list should be treated as a list of commands, if the user "clicks" a command from the list its action performed method is invoked.
Parameters
commandList: true for the list to be treated as a command list
-
isIgnoreFocusComponentWhenUnfocused
public boolean isIgnoreFocusComponentWhenUnfocused()Indicates whether the list should not paint the focus component if the list itself has no focus.
Returns
the ignoreFocusComponentWhenUnfocused
-
setIgnoreFocusComponentWhenUnfocused
public void setIgnoreFocusComponentWhenUnfocused(boolean ignoreFocusComponentWhenUnfocused) Indicates whether the list should not paint the focus component if the list itself has no focus.
Parameters
ignoreFocusComponentWhenUnfocused: true to ignore the focus component false otherwise
-
isMutableRendererBackgrounds
public boolean isMutableRendererBackgrounds()Indicates that the background of a cell renderer might mutate between one entry and the next, it is recommended that this flag remains false for performance reasons.
Returns
the value of the flag
-
setMutableRendererBackgrounds
public void setMutableRendererBackgrounds(boolean mutableRendererBackgrounds) Indicates that the background of a cell renderer might mutate between one entry and the next, it is recommended that this flag remains false for performance reasons.
Parameters
mutableRendererBackgrounds: the new value for the flag
-
getListSizeCalculationSampleCount
public int getListSizeCalculationSampleCount()Indicates the number of elements the list should check to determine the element sizes. This is ignored when a rendering prototype is present.
Returns
the listSizeCalculationSampleCount
-
setListSizeCalculationSampleCount
public void setListSizeCalculationSampleCount(int listSizeCalculationSampleCount) Indicates the number of elements the list should check to determine the element sizes. This is ignored when a rendering prototype is present.
Parameters
listSizeCalculationSampleCount: the listSizeCalculationSampleCount to set
-
isLongPointerPressActionEnabled
public boolean isLongPointerPressActionEnabled()Enable/disable list action on long pointer press event
Returns
the longPointerPressAction
-
setLongPointerPressActionEnabled
public void setLongPointerPressActionEnabled(boolean longPointerPressAction) Enable/disable list action on long pointer press event
Parameters
longPointerPressAction: the longPointerPressAction to set
-
setListCellRenderer
Sets the renderer which is used to draw list elements
Parameters
renderer: cell renderer instance
Deprecated
-
getRenderer
Returns the renderer which is used to draw list elements
Returns
the renderer which is used to draw list elements
-
setRenderer
Sets the renderer which is used to draw list elements
Parameters
renderer: cell renderer instance
-
getOrientation
public int getOrientation()Returns the list orientation
Returns
the list orientation HORIZONTAL or VERTICAL
See also
-
#HORIZONTAL
-
#VERTICAL
-
-
setOrientation
public void setOrientation(int orientation) Sets the list orientation HORIZONTAL or VERTICAL
Parameters
orientation: the list orientation HORIZONTAL or VERTICAL
See also
-
#HORIZONTAL
-
#VERTICAL
-
refreshTheme
public void refreshTheme(boolean merge) Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!
Parameters
merge: indicates if the current styles should be merged with the new styles
- Overrides:
refreshThemein classComponent
-
scrollRectToVisible
Makes sure the selected index is visible if it is not in the current view rect the list will scroll so it fits within
Parameters
rect: the rectangle area to scroll to
-
setHandlesInput
public void setHandlesInput(boolean b) Prevents key events from being grabbed for focus traversal. E.g. a list component might use the arrow keys for internal navigation so it will switch this flag to true in order to prevent the focus manager from moving to the next component.
Parameters
handlesInput: @param handlesInput indicates whether key events can be grabbed for focus traversal
- Overrides:
setHandlesInputin classComponent
-
fireClicked
protected void fireClicked()When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method in order to allow 3 button devices to work properly. When overriding this method you should also override isSelectableInteraction to indicate that a command is placed appropriately on top of the fire key for 3 soft button phones.- Overrides:
fireClickedin classComponent
-
isSelectableInteraction
protected boolean isSelectableInteraction()This method allows a component to indicate that it is interested in an "implicit" select command to appear in the "fire" button when 3 softbuttons are defined in a device.
Returns
true if this is a selectable interaction
- Overrides:
isSelectableInteractionin classComponent
-
keyReleased
public void keyReleased(int keyCode) If this Component is focused, the key released event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyReleasedin classComponent
-
keyPressed
public void keyPressed(int keyCode) If this Component is focused, the key pressed event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyPressedin classComponent
-
paint
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: the component graphics
-
shouldRenderSelection
protected boolean shouldRenderSelection()Allows subclasses to override the selection rendering for the component, specifically the spinner in some themes
Returns
true to render the selection, false otherwise.
-
addSelectionListener
Invoked to indicate interest in future selection events
Parameters
l: the selection listener to be added
-
removeSelectionListener
Invoked to indicate no further interest in future selection events
Parameters
l: the selection listener to be removed
-
addActionListener
Allows binding a listener to user selection actions
Parameters
l: the action listener to be added
- Specified by:
addActionListenerin interfaceActionSource<T>
-
getActionListeners
This method allows extracting the action listeners from the current list
Returns
vector containing the action listeners on the list
Deprecated
use getListeners instead
-
getListeners
This method allows extracting the action listeners from the current list
Returns
Collection containing the action listeners on the list
-
removeActionListener
Allows binding a listener to user selection actions
Parameters
l: the action listener to be removed
- Specified by:
removeActionListenerin interfaceActionSource<T>
-
fireActionEvent
protected void fireActionEvent() -
fireActionEvent
Triggers the event to the listeners
Parameters
a: the event to fire
-
setInputOnFocus
public void setInputOnFocus(boolean inputOnFocus) A list can start handling input implicitly upon gaining focus, this can make for a more intuitive UI when no other focus elements exist or when their use case is infrequent. However, it might be odd in some cases where the list "steals" focus.
Parameters
inputOnFocus: @param inputOnFocus true is a list can start handling input implicitly upon gaining focus
-
setPaintFocusBehindList
public void setPaintFocusBehindList(boolean paintFocusBehindList) This method determines if the animated focus is drawn on top of the List or behind the List when moving.
Parameters
paintFocusBehindList
-
getItemGap
public int getItemGap()Returns the gap between items
Returns
the gap between items
-
setItemGap
public void setItemGap(int itemGap) Set the gap between items
Parameters
itemGap: the gap between items
-
getRenderingPrototype
See set rendering prototype
Returns
the value of the rendering prototype
See also
- #setRenderingPrototype(java.lang.Object)
-
setRenderingPrototype
The rendering prototype is optionally used in calculating the size of the List and is recommended for performance reasons. You should invoke it with an object representing a theoretical value in the list which will be used to calculate the size required for each element in the list.
This allows list size calculations to work across look and feels and allows developers to predetermine size for list elements.
e.g. For a list of Strings which you would like to always be 5 characters wide you can use a prototype "XXXXX" which would use the preferred size of the XXXXX String to determine the size of the list element. E.g. for a list of dates you can use new Date(30, 12, 00) etc..
The example below was designed for
com.codename1.ui.list.MultiListbut should work for any list. Its goal is to render 2 lines of text with 20 characters and a 5mm square icon:Map proto = new HashMap<>(); map.put("Line1", "WWWWWWWWWWWWWWWWWWWW"); map.put("Line2", "WWWWWWWWWWWWWWWWWWWW"); int mm5 = Display.getInstance().convertToPixels(5, true); map.put("icon", Image.create(mm5, mm5)); myMultiList.setRenderingPrototype(map);Parameters
renderingPrototype: @param renderingPrototype a value that can be passed to the renderer to indicate the preferred size of a list component.
-
longPointerPress
public void longPointerPress(int x, int y) If this Component is focused this method is invoked when the user presses and holds the pointer on the Component- Overrides:
longPointerPressin classComponent
-
pointerPressed
public void pointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerPressedin classComponent
-
-
pointerHover
public void pointerHover(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerHoverin classComponent
-
-
pointerDragged
public void pointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerDraggedin classComponent
-
-
getSelectedRect
Returns the component bounds with absolute screen coordinates, for components that include an internal selection behavior and are not containers (currently only List) this method allows returning the position of the selection itself which is useful for things such as the popup dialog and similar UI's that need to reference the position of the selection externally
Returns
the bounds of the component with absolute screen coordinates
- Overrides:
getSelectedRectin classComponent
-
setFireOnClick
public void setFireOnClick(boolean fireOnClick) This method determines if the List fires the action event when the pointer was clicked on one of the items, or only if the item was the selected item By default the value is true, this setting is only relevant for none fixed Lists
Parameters
fireOnClick
-
pointerHoverReleased
public void pointerHoverReleased(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerHoverReleasedin classComponent
-
-
pointerReleased
public void pointerReleased(int x, int y) If this Component is focused, the pointer released event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerReleasedin classComponent
-
-
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
- Overrides:
calcPreferredSizein classComponent
-
addItem
Allows adding an element to a list if the underlying model supports this, notice that it is an optional operation and if the model does not support it (default list model does) then this operation may failed.
Parameters
item: the item to be added to a list model
-
getFixedSelection
public int getFixedSelection()Indicates whether selection is fixable to place in which case all the elements in the list move and selection stays in place.
Returns
one of: FIXED_NONE, FIXED_TRAIL, FIXED_LEAD, FIXED_CENTER, FIXED_NONE_CYCLIC
-
setFixedSelection
public void setFixedSelection(int fixedSelection) Indicates whether selection is fixable to place in which case all the elements in the list move and selection stays in place.
Parameters
fixedSelection: @param fixedSelection one of: FIXED_NONE, FIXED_TRAIL, FIXED_LEAD, FIXED_CENTER, FIXED_NONE_CYCLIC
-
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.Displayclass.Returns
true if a repaint is desired or false if no repaint is necessary
-
isTactileTouch
protected boolean isTactileTouch(int x, int y) Elaborate components might not provide tactile feedback for all their areas (e.g. Lists) this method defaults to returning the value of isTactileTouch
Parameters
-
x: the x position -
y: the y position
Returns
True if the device should vibrate
- Overrides:
isTactileTouchin classComponent
-
-
setScrollToSelected
public void setScrollToSelected(boolean scrollToSelected) This flag indicates to the List if the List should scroll to the selected element when it's been initialized.
Parameters
scrollToSelected: @param scrollToSelected if true the List scrolls to the selected element when It's been initialized.
-
getGridPosY
protected int getGridPosY()This method should be implemented correctly by subclasses to make snap to grid functionality work as expected. Returns the ideal grid Y position closest to the current Y position.
Returns
a valid Y position in the grid
- Overrides:
getGridPosYin classComponent
-
getGridPosX
protected int getGridPosX()This method should be implemented correctly by subclasses to make snap to grid functionality work as expected. Returns the ideal grid X position closest to the current X position.
Returns
a valid Y position in the grid
- Overrides:
getGridPosXin classComponent
-
paramString
Returns a string representing the state of this component. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be
null.Returns
a string representation of this component's state
- Overrides:
paramStringin classComponent
-
getHint
Returns the hint text
Returns
the hint text or null
-
setHint
Sets the TextArea hint text, the hint text is displayed on the TextArea When there is no text in the TextArea
Parameters
hint: the hint text to display
-
getHintIcon
Returns the hint icon
Returns
the hint icon
-
setHintIcon
Sets the TextArea hint icon, the hint is displayed on the TextArea When there is no text in the TextArea
Parameters
icon: the icon
-
setHint
-