- All Implemented Interfaces:
javafx.css.Styleable,javafx.event.EventTarget,javafx.scene.control.Skinnable
partial ratings (i.e. not whole numbers and
dependent upon where the user clicks in the control) and
updating the rating on hover. Read on for
more examples!
Examples
It can be hard to appreciate some of the features of the Rating control, so hopefully the following screenshots will help. Firstly, here is what the standard (horizontal) Rating control looks like when it has five stars, and a rating of two:
To create a Rating control that looks like this is simple:
final Rating rating = new Rating();
This creates a default horizontal rating control. To create a vertical Rating control, simply change the orientation, as such:
final Rating rating = new Rating();
rating.setOrientation(Orientation.VERTICAL);
The end result of making this one line change is shown in the screenshot
below:
One of the features of the Rating control is that it doesn't just allow
for 'integer' ratings: it also allows for the user to click anywhere within
the rating area to set a 'float' rating. This is hard to describe, but easy
to show in a picture:
In essence, in the screenshot above, the user clicked roughly in the
middle of the third star. This results in a rating of approximately 2.44.
To enable partial ratings, simply do the
following when instantiating the Rating control:
final Rating rating = new Rating();
rating.setPartialRating(true);
So far all of the Rating controls demonstrated above have
required the user to click on the stars to register their rating. This may not
be the preferred user interaction - often times the preferred approach is to
simply allow for the rating to be registered by the user hovering their mouse
over the rating stars. This mode is also supported by the Rating control,
using the update on hover property, as such:
final Rating rating = new Rating();
rating.setUpdateOnHover(true);
It is also allowable to have a Rating control that both updates on hover and allows for partial values: the 'golden fill' of the default graphics will automatically follow the users mouse as they move it along the Rating scale. To enable this, just set both properties to true.
-
Property Summary
PropertiesTypePropertyDescriptionfinal javafx.beans.property.IntegerPropertyThe maximum-allowed rating value.final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> TheOrientationof theRating- this can either be horizontal or vertical.final javafx.beans.property.BooleanPropertyIf true this allows for users to set a rating as a floating point value.final javafx.beans.property.DoublePropertyThe current rating value.final javafx.beans.property.BooleanPropertyIf true this allows for therating propertyto be updated simply by the user hovering their mouse over the control.Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltipProperties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, widthProperties inherited from class javafx.scene.Parent
needsLayoutProperties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible -
Field Summary
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZEFields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT -
Constructor Summary
ConstructorsConstructorDescriptionRating()Creates a default instance with a minimum rating of 0 and a maximum rating of 5.Rating(int max) Creates a default instance with a minimum rating of 0 and a maximum rating as provided by the argument.Rating(int max, int rating) Creates a Rating instance with a minimum rating of 0, a maximum rating as provided by themaxargument, and a current rating as provided by theratingargument. -
Method Summary
Modifier and TypeMethodDescriptionprotected javafx.scene.control.Skin<?> final intgetMax()Returns the maximum-allowed rating value.final javafx.geometry.OrientationReturns theOrientationof theRating- this can either be horizontal or vertical.final doubleReturns the current rating value.protected final StringgetUserAgentStylesheet(Class<?> clazz, String fileName) A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once.final booleanReturns whetherpartial ratingsupport is enabled or not.final booleanReturns whetherupdate on hoversupport is enabled or not.final javafx.beans.property.IntegerPropertyThe maximum-allowed rating value.final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> TheOrientationof theRating- this can either be horizontal or vertical.final javafx.beans.property.BooleanPropertyIf true this allows for users to set a rating as a floating point value.final javafx.beans.property.DoublePropertyThe current rating value.final voidsetMax(int value) Sets the maximum-allowed rating value.final voidsetOrientation(javafx.geometry.Orientation value) Sets theOrientationof theRating- this can either be horizontal or vertical.final voidsetPartialRating(boolean value) Sets whetherpartial ratingsupport is enabled or not.final voidsetRating(double value) Sets the current rating value.final voidsetUpdateOnHover(boolean value) Sets whetherupdate on hoversupport is enabled or not.final javafx.beans.property.BooleanPropertyIf true this allows for therating propertyto be updated simply by the user hovering their mouse over the control.Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinProperty, tooltipPropertyMethods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthPropertyMethods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBoundsMethods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visiblePropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
rating
public final javafx.beans.property.DoubleProperty ratingPropertyThe current rating value.- See Also:
-
max
public final javafx.beans.property.IntegerProperty maxPropertyThe maximum-allowed rating value.- See Also:
-
orientation
public final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> orientationPropertyTheOrientationof theRating- this can either be horizontal or vertical.- See Also:
-
partialRating
public final javafx.beans.property.BooleanProperty partialRatingPropertyIf true this allows for users to set a rating as a floating point value. In other words, the range of the rating 'stars' can be thought of as a range between [0, max], and whereever the user clicks will be calculated as the new rating value. If this is false the more typical approach is used where the selected 'star' is used as the rating.- See Also:
-
updateOnHover
public final javafx.beans.property.BooleanProperty updateOnHoverPropertyIf true this allows for therating propertyto be updated simply by the user hovering their mouse over the control. If false the user is required to click on their preferred rating to register the new rating with this control.- See Also:
-
-
Constructor Details
-
Rating
public Rating()Creates a default instance with a minimum rating of 0 and a maximum rating of 5. -
Rating
public Rating(int max) Creates a default instance with a minimum rating of 0 and a maximum rating as provided by the argument.- Parameters:
max- The maximum allowed rating value.
-
Rating
public Rating(int max, int rating) Creates a Rating instance with a minimum rating of 0, a maximum rating as provided by themaxargument, and a current rating as provided by theratingargument.- Parameters:
max- The maximum allowed rating value.
-
-
Method Details
-
createDefaultSkin
protected javafx.scene.control.Skin<?> createDefaultSkin()- Overrides:
createDefaultSkinin classjavafx.scene.control.Control
-
getUserAgentStylesheet
- Overrides:
getUserAgentStylesheetin classjavafx.scene.layout.Region
-
ratingProperty
public final javafx.beans.property.DoubleProperty ratingProperty()The current rating value.- Returns:
- the
ratingproperty - See Also:
-
setRating
public final void setRating(double value) Sets the current rating value. -
getRating
public final double getRating()Returns the current rating value. -
maxProperty
public final javafx.beans.property.IntegerProperty maxProperty()The maximum-allowed rating value.- Returns:
- the
maxproperty - See Also:
-
setMax
public final void setMax(int value) Sets the maximum-allowed rating value. -
getMax
public final int getMax()Returns the maximum-allowed rating value. -
orientationProperty
public final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> orientationProperty()TheOrientationof theRating- this can either be horizontal or vertical.- Returns:
- the
orientationproperty - See Also:
-
setOrientation
public final void setOrientation(javafx.geometry.Orientation value) Sets theOrientationof theRating- this can either be horizontal or vertical. -
getOrientation
public final javafx.geometry.Orientation getOrientation()Returns theOrientationof theRating- this can either be horizontal or vertical. -
partialRatingProperty
public final javafx.beans.property.BooleanProperty partialRatingProperty()If true this allows for users to set a rating as a floating point value. In other words, the range of the rating 'stars' can be thought of as a range between [0, max], and whereever the user clicks will be calculated as the new rating value. If this is false the more typical approach is used where the selected 'star' is used as the rating.- Returns:
- the
partialRatingproperty - See Also:
-
setPartialRating
public final void setPartialRating(boolean value) Sets whetherpartial ratingsupport is enabled or not. -
isPartialRating
public final boolean isPartialRating()Returns whetherpartial ratingsupport is enabled or not. -
updateOnHoverProperty
public final javafx.beans.property.BooleanProperty updateOnHoverProperty()If true this allows for therating propertyto be updated simply by the user hovering their mouse over the control. If false the user is required to click on their preferred rating to register the new rating with this control.- Returns:
- the
updateOnHoverproperty - See Also:
-
setUpdateOnHover
public final void setUpdateOnHover(boolean value) Sets whetherupdate on hoversupport is enabled or not. -
isUpdateOnHover
public final boolean isUpdateOnHover()Returns whetherupdate on hoversupport is enabled or not. -
getUserAgentStylesheet
A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once. Caches the external form of the resource.- Parameters:
clazz- the class used for the resource lookupfileName- the name of the user agent stylesheet- Returns:
- the external form of the user agent stylesheet (the path)
-