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

public class CircularSlider

  1. Object
  2. Component
  3. CircularSlider

ImplementsAnimation, Editable, StyleListener

A round slider: a value picked by dragging a thumb along an arc, as on a thermostat or a volume knob.

CircularSlider dial = new CircularSlider(0, 100);
dial.setValue(40);
dial.addActionListener(e -> Log.p("Value " + dial.getValue()));

Angles are in degrees, with 0 at three o’clock and positive values counter clockwise, the convention of Graphics.drawArc. The default arc starts at 225 (lower left) and sweeps -270 degrees, clockwise over the top to the lower right. A tap or drag anywhere on the component moves the thumb to the nearest point of the arc. Left/down and right/up keys change the value by one step. The filled part uses the accent colour of the UIID CircularSlider, the rest a track colour.

Constructors

public CircularSlider()A slider from 0 to 100.
public CircularSlider(int min, int max)A slider over a range.

Methods

public int getMin()The smallest value.
public int getMax()The largest value.
public int getValue()The current value.
public void setValue(int value)Sets the value without notifying listeners.
public void setStep(int step)Sets the amount a key press changes the value and the granularity of a drag.
public int getStep()The step.
public void setArc(int startAngle, int sweepAngle)Sets the arc the thumb travels along.
public int getStartAngle()Where the arc starts.
public int getSweepAngle()The extent of the arc.
public void setEditable(boolean editable)Whether the user can change the value.
public boolean isEditable()Whether the user can change the value.
public void addActionListener(ActionListener l)Listens for the user changing the value.
public void removeActionListener(ActionListener l)Removes a listener.
public int valueAtAngle(double angle)The value at an angle, snapped to the step.
public double angleForValue(int v)The angle of the thumb for a value.
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 keyReleased(int keyCode)If this Component is focused, the key released event will call this method
protected boolean isStickyDrag()Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries.
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 String getAccessibilityText()Returns the text that describes this component to assistive technologies.

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, 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, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initUnselectedStyle, 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, laidOut, deinitialize, 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, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

CircularSlider

public CircularSlider()
A slider from 0 to 100.

CircularSlider

public CircularSlider(int min, int max)
A slider over a range.

Parameters

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

Method details

getMin

public int getMin()
The smallest value.

Returns

the minimum

getMax

public int getMax()
The largest value.

Returns

the maximum

getValue

public int getValue()
The current value.

Returns

a value from #getMin() to #getMax()

setValue

public void setValue(int value)
Sets the value without notifying listeners.

Parameters

value int
the value, clamped to the range

setStep

public void setStep(int step)
Sets the amount a key press changes the value and the granularity of a drag.

Parameters

step int
a positive step

getStep

public int getStep()
The step.

Returns

the amount a key press changes the value

setArc

public void setArc(int startAngle, int sweepAngle)
Sets the arc the thumb travels along.

Parameters

startAngle int
where the minimum sits, in degrees, 0 at three o’clock
sweepAngle int
the extent of the arc; negative runs clockwise. Its magnitude is 1 to 360

getStartAngle

public int getStartAngle()
Where the arc starts.

Returns

the start angle in degrees

getSweepAngle

public int getSweepAngle()
The extent of the arc.

Returns

the sweep in degrees, negative for clockwise

setEditable

public void setEditable(boolean editable)
Whether the user can change the value.

Parameters

editable boolean
false to make the slider display only

isEditable

public boolean isEditable()
Whether the user can change the value.

Returns

true unless turned off

addActionListener

public void addActionListener(ActionListener l)
Listens for the user changing the value.

Parameters

l ActionListener
the listener

removeActionListener

public void removeActionListener(ActionListener l)
Removes a listener.

Parameters

l ActionListener
the listener

valueAtAngle

public int valueAtAngle(double angle)
The value at an angle, snapped to the step. An angle outside the arc goes to the nearer end.

Parameters

angle double
degrees, 0 at three o’clock, counter clockwise

Returns

the value the thumb would show there

angleForValue

public double angleForValue(int v)
The angle of the thumb for a value.

Parameters

v int
a value in the range

Returns

degrees, 0 at three o’clock, counter clockwise

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

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.

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

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

getAccessibilityText

public String getAccessibilityText()
Returns the text that describes this component to assistive technologies. If no text was set explicitly, this method attempts to derive a description from the component’s label or content.

Returns

accessibility description or null if none