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

public class RangeSlider

  1. Object
  2. Component
  3. RangeSlider

ImplementsAnimation, Editable, StyleListener

A slider with two thumbs that selects a range, such as a price filter or a time window.

A price range slider with both thumbs

Form form = new Form("Filters", BoxLayout.y());
RangeSlider price = new RangeSlider(0, 500, 50, 300);
price.setStep(10);
Label shown = new Label("$50 - $300");
price.addActionListener(e -> shown.setText(
        "$" + price.getLowerValue() + " - $" + price.getUpperValue()));
form.add(price).add(shown);
form.show();

Dragging moves whichever thumb is nearer the touch; the thumbs never cross. Listeners fire while the value changes and once more when the drag ends, with #isAdjusting() false for that last event.

UIIDs: RangeSlider for the component. The fill takes the foreground of RangeSliderFill and the track the background of RangeSliderTrack when the theme defines them, and otherwise follow the theme’s Slider colours.

Constructors

public RangeSlider()A slider over 0 to 100 selecting all of it.
public RangeSlider(int min, int max, int lower, int upper)A slider over min to max selecting lower to upper.

Methods

protected void initUnselectedStyle(Style unselectedStyle)Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.
public int getMinValue()The smallest value.
public int getMaxValue()The largest value.
public int getLowerValue()The start of the selected range.
public int getUpperValue()The end of the selected range.
public final void setRange(int lower, int upper)Sets the selected range.
public void setBounds(int min, int max)Sets the slider’s bounds, keeping the selection inside them.
public int getStep()The increment the values snap to.
public void setStep(int step)Sets the increment the values snap to, counted from the minimum.
public boolean isAdjusting()True while the user is dragging a thumb.
public void addActionListener(ActionListener l)Adds a listener called whenever the range changes.
public void removeActionListener(ActionListener l)Removes a listener.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public void paint(Graphics g)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.
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
protected boolean isStickyDrag()Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries.
public void keyReleased(int keyCode)If this Component is focused, the key released event will call this method

Inherited fields

Inherited methods

From Component

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

RangeSlider

public RangeSlider()
A slider over 0 to 100 selecting all of it.

RangeSlider

public RangeSlider(int min, int max, int lower, int upper)
A slider over min to max selecting lower to upper.

Parameters

min int
the smallest value
max int
the largest value, greater than min
lower int
the start of the selected range
upper int
the end of the selected range

Method details

initUnselectedStyle

protected void initUnselectedStyle(Style unselectedStyle)
Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

Parameters

unselectedStyle Style
The unselected style.

getMinValue

public int getMinValue()
The smallest value.

Returns

the minimum

getMaxValue

public int getMaxValue()
The largest value.

Returns

the maximum

getLowerValue

public int getLowerValue()
The start of the selected range.

Returns

the lower value

getUpperValue

public int getUpperValue()
The end of the selected range.

Returns

the upper value

setRange

public final void setRange(int lower, int upper)
Sets the selected range. Values are clamped to the slider’s bounds and snapped to the step, and swapped if given in the wrong order.

Parameters

lower int
the start of the range
upper int
the end of the range

setBounds

public void setBounds(int min, int max)
Sets the slider’s bounds, keeping the selection inside them.

Parameters

min int
the smallest value
max int
the largest value, greater than min

getStep

public int getStep()
The increment the values snap to.

Returns

the step, 1 by default

setStep

public void setStep(int step)
Sets the increment the values snap to, counted from the minimum.

Parameters

step int
a positive step

isAdjusting

public boolean isAdjusting()
True while the user is dragging a thumb. Listeners hear every change during a drag with this true, then once more with it false when the finger lifts; a listener that runs a search can ignore the first kind.

Returns

whether a drag is in progress

addActionListener

public void addActionListener(ActionListener l)
Adds a listener called whenever the range changes.

Parameters

l ActionListener
the listener

removeActionListener

public void removeActionListener(ActionListener l)
Removes a listener.

Parameters

l ActionListener
the listener

calcPreferredSize

protected Dimension 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

paint

public void paint(Graphics g)
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 Graphics
the component graphics

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

isStickyDrag

protected boolean isStickyDrag()
Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. This is useful for spinners etc. where the motion might continue beyond the size of the component

Returns

false by default

keyReleased

public void keyReleased(int keyCode)
If this Component is focused, the key released event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.