public abstract class ButtonList extends Container implements DataChangedListener, SelectionListener, ActionListener, ActionSource
Switch (SwitchList), RadioButton (RadioButtonList,
and CheckBox (CheckBoxList).
This abstraction allows you to work with a set of toggle buttons as a single unit. It uses
a ListModel to store the toggle options, and will automatically stay in sync with its model
when options are added or removed, or the selection is changed.
Switch List in a FlowLayout:
SwitchList switchList = new SwitchList(new DefaultListModel("Red", "Green", "Blue", "Indigo"));
switchList.setLayout(new FlowLayout());
Switch List in a BoxLayout.Y:
*
SwitchList switchList = new SwitchList(new DefaultListModel("Red", "Green", "Blue", "Indigo"));
switchList.setLayout(BoxLayout.y());
Switch List in a Grid Layout:
Switch List in a Table Layout:
2 Columns:
SwitchList switchList = new SwitchList(new DefaultListModel("Red", "Green", "Blue", "Indigo"));
switchList.setLayout(new TableLayout(switchList.getComponentCount()/2+1, 2));
3 Columns:
SwitchList switchList = new SwitchList(new DefaultListModel("Red", "Green", "Blue", "Indigo"));
switchList.setLayout(new TableLayout(switchList.getComponentCount()/3+1, 3));
| Modifier and Type | Class and Description |
|---|---|
static interface |
ButtonList.Decorator<M,V extends Component>
An interface that can be implemented to provide custom decoration/undecoration of the buttons as they are
created/removed.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
ready |
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_CURSORADDED, CHANGED, REMOVED| Constructor and Description |
|---|
ButtonList(ListModel model)
Creates a new ButtonList.
|
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(ActionEvent evt)
Invoked when an action occurred on a component
|
void |
addActionListener(ActionListener l)
Add a listener to be notified when any of the buttons in the list are pressed.
|
void |
addDecorator(ButtonList.Decorator decorator)
Adds a decorator that can be used to customize a button when it is created
|
protected abstract Component |
createButton(Object model)
Creates a new button for this list.
|
void |
dataChanged(int status,
int index)
Invoked when there was a change in the underlying model
|
protected Component |
decorateComponent(Object modelItem,
Component b)
Decorates buttons.
|
protected void |
fireReady()
This should be called by the concrete implementation once it is ready to generate the
buttons.
|
ListModel |
getModel()
Returns the model.
|
MultipleSelectionListModel |
getMultiListModel()
For multi-selection models (e.g.
|
abstract boolean |
isAllowMultipleSelection()
Returns true for lists that allow multiple selection.
|
protected void |
onReady(Runnable r)
Wrap any calls that requires that the infrastructure is ready inside this.
|
void |
refresh()
Refreshes the container - regenerating all of the buttons in the list from
the model.
|
void |
removeActionListener(ActionListener l)
Remove a listener so that it no longer is notified when buttons in the list are pressed.
|
void |
removeDecorator(ButtonList.Decorator decorator)
Removes a decorator.
|
void |
selectionChanged(int oldSelected,
int newSelected)
Indicates the selection changed in the underlying list model
|
void |
setCellUIID(String uiid)
Sets the UIID for cells of the list.
|
void |
setLayout(Layout layout)
Sets the layout for the list.
|
void |
setModel(ListModel model) |
protected abstract void |
setSelected(Component button,
boolean selected)
Sets the given button's selected state.
|
protected Component |
undecorateComponent(Component b)
Undecorates buttons.
|
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, paintBackground, paintBorderBackground, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesaddDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, 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, paintBackgrounds, paintBorder, 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, 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, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainspublic ButtonList(ListModel model)
model - The options. Each will be represented by a button.protected void onReady(Runnable r)
r - Will be run when buttons are ready to be generated.protected void fireReady()
public MultipleSelectionListModel getMultiListModel()
MultiSelectionListModel. Otherwise it will return null.public ListModel getModel()
public abstract boolean isAllowMultipleSelection()
CheckBoxList, and SwitchList support multiple selection.
RadioButtonList does not.protected abstract Component createButton(Object model)
model - protected abstract void setSelected(Component button, boolean selected)
button - The button (in the form produced by createButton(java.lang.Object).selected - Whether the button is selected or not.public void setModel(ListModel model)
public void setLayout(Layout layout)
setLayout in class Containerlayout - The layout to use. Only layouts that don't require constraints in Container.add(java.lang.Object, com.codename1.ui.Component)
may be used. E.g. FlowLayout, BoxLyout, TableLayout, GridLayout are all fine.public void refresh()
protected Component decorateComponent(Object modelItem, Component b)
b - The button in the form returned by createButton(java.lang.Object)protected Component undecorateComponent(Component b)
b - The button in the form returned by createButton(java.lang.Object)public void dataChanged(int status,
int index)
DataChangedListenerdataChanged in interface DataChangedListenerstatus - the type data change; REMOVED, ADDED or CHANGEDindex - item index in a list modelpublic void selectionChanged(int oldSelected,
int newSelected)
SelectionListenerselectionChanged in interface SelectionListeneroldSelected - old selected index in list modelnewSelected - new selected index in list modelpublic void actionPerformed(ActionEvent evt)
ActionListeneractionPerformed in interface ActionListenerevt - event object describing the source of the action as well as
its triggerpublic void addActionListener(ActionListener l)
addActionListener in interface ActionSourcel - public void removeActionListener(ActionListener l)
removeActionListener in interface ActionSourcel - public void setCellUIID(String uiid)
createButton(java.lang.Object) method.uiid - public void addDecorator(ButtonList.Decorator decorator)
decorator - A decorator.public void removeDecorator(ButtonList.Decorator decorator)
decorator -