public class Rating
extends javafx.scene.control.Control
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!
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.
| Type | Property and Description |
|---|---|
javafx.beans.property.IntegerProperty |
max
The maximum-allowed rating value.
|
javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> |
orientation
The
Orientation of the Rating - this can either be
horizontal or vertical. |
javafx.beans.property.BooleanProperty |
partialRating
If true this allows for users to set a rating as a floating point value.
|
javafx.beans.property.DoubleProperty |
rating
The current rating value.
|
javafx.beans.property.BooleanProperty |
updateOnHover
If true this allows for the
rating property to
be updated simply by the user hovering their mouse over the control. |
contextMenu, skinClassName, skin, tooltipbackground, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, widthaccessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, impl_showMnemonics, impl_treeVisible, 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, visible| Constructor and Description |
|---|
Rating()
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 the
max argument, and a current rating as provided
by the rating argument. |
| Modifier and Type | Method and Description |
|---|---|
protected javafx.scene.control.Skin<?> |
createDefaultSkin() |
int |
getMax()
Returns the maximum-allowed rating value.
|
javafx.geometry.Orientation |
getOrientation()
Returns the
Orientation of the Rating - this can either
be horizontal or vertical. |
double |
getRating()
Returns the current rating value.
|
java.lang.String |
getUserAgentStylesheet() |
protected java.lang.String |
getUserAgentStylesheet(java.lang.Class<?> clazz,
java.lang.String fileName)
A helper method that ensures that the resource based lookup of the user
agent stylesheet only happens once.
|
boolean |
isPartialRating()
Returns whether
partial rating support is
enabled or not. |
boolean |
isUpdateOnHover()
Returns whether
update on hover support is
enabled or not. |
javafx.beans.property.IntegerProperty |
maxProperty()
The maximum-allowed rating value.
|
javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> |
orientationProperty()
The
Orientation of the Rating - this can either be
horizontal or vertical. |
javafx.beans.property.BooleanProperty |
partialRatingProperty()
If true this allows for users to set a rating as a floating point value.
|
javafx.beans.property.DoubleProperty |
ratingProperty()
The current rating value.
|
void |
setMax(int value)
Sets the maximum-allowed rating value.
|
void |
setOrientation(javafx.geometry.Orientation value)
Sets the
Orientation of the Rating - this can either be
horizontal or vertical. |
void |
setPartialRating(boolean value)
Sets whether
partial rating support is
enabled or not. |
void |
setRating(double value)
Sets the current rating value.
|
void |
setUpdateOnHover(boolean value)
Sets whether
update on hover support is
enabled or not. |
javafx.beans.property.BooleanProperty |
updateOnHoverProperty()
If true this allows for the
rating property to
be updated simply by the user hovering their mouse over the control. |
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getSkin, getTooltip, impl_cssGetFocusTraversableInitialValue, impl_processCSS, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipPropertybackgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, impl_computeContains, impl_computeGeomBounds, impl_computeLayoutBounds, impl_createPeer, impl_notifyLayoutBoundsChanged, impl_pickNodeLocal, impl_updatePeer, 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, snapSize, snapSpace, snapToPixelProperty, widthPropertygetChildren, getChildrenUnmodifiable, getImpl_traversalEngine, getManagedChildren, getStylesheets, impl_getAllParentStylesheets, impl_processMXNode, impl_traversalEngineProperty, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setImpl_traversalEngine, setNeedsLayout, updateBoundsaccessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, containsBounds, 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, 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, hasProperties, hoverProperty, idProperty, impl_clearDirty, impl_computeIntersects, impl_cssGetCursorInitialValue, impl_findStyles, impl_geomChanged, impl_getLeafTransform, impl_getMatchingStyles, impl_getPeer, impl_getPivotX, impl_getPivotY, impl_getPivotZ, impl_getStyleMap, impl_hasTransforms, impl_intersects, impl_intersectsBounds, impl_isDirty, impl_isDirtyEmpty, impl_isShowMnemonics, impl_isTreeVisible, impl_layoutBoundsChanged, impl_markDirty, impl_pickNode, impl_processCSS, impl_reapplyCSS, impl_setShowMnemonics, impl_setStyleMap, impl_showMnemonicsProperty, impl_syncPeer, impl_transformsChanged, impl_traverse, impl_treeVisibleProperty, 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, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, visiblePropertypublic final javafx.beans.property.DoubleProperty ratingProperty
getRating(),
setRating(double)public final javafx.beans.property.IntegerProperty maxProperty
getMax(),
setMax(int)public final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> orientationProperty
Orientation of the Rating - this can either be
horizontal or vertical.getOrientation(),
setOrientation(Orientation)public final javafx.beans.property.BooleanProperty partialRatingProperty
isPartialRating(),
setPartialRating(boolean)public final javafx.beans.property.BooleanProperty updateOnHoverProperty
rating property to
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.isUpdateOnHover(),
setUpdateOnHover(boolean)public Rating()
public Rating(int max)
max - The maximum allowed rating value.public Rating(int max,
int rating)
max argument, and a current rating as provided
by the rating argument.max - The maximum allowed rating value.protected javafx.scene.control.Skin<?> createDefaultSkin()
createDefaultSkin in class javafx.scene.control.Controlpublic java.lang.String getUserAgentStylesheet()
getUserAgentStylesheet in class javafx.scene.layout.Regionpublic final javafx.beans.property.DoubleProperty ratingProperty()
getRating(),
setRating(double)public final void setRating(double value)
public final double getRating()
public final javafx.beans.property.IntegerProperty maxProperty()
getMax(),
setMax(int)public final void setMax(int value)
public final int getMax()
public final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> orientationProperty()
Orientation of the Rating - this can either be
horizontal or vertical.getOrientation(),
setOrientation(Orientation)public final void setOrientation(javafx.geometry.Orientation value)
Orientation of the Rating - this can either be
horizontal or vertical.public final javafx.geometry.Orientation getOrientation()
Orientation of the Rating - this can either
be horizontal or vertical.public final javafx.beans.property.BooleanProperty partialRatingProperty()
isPartialRating(),
setPartialRating(boolean)public final void setPartialRating(boolean value)
partial rating support is
enabled or not.public final boolean isPartialRating()
partial rating support is
enabled or not.public final javafx.beans.property.BooleanProperty updateOnHoverProperty()
rating property to
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.isUpdateOnHover(),
setUpdateOnHover(boolean)public final void setUpdateOnHover(boolean value)
update on hover support is
enabled or not.public final boolean isUpdateOnHover()
update on hover support is
enabled or not.protected final java.lang.String getUserAgentStylesheet(java.lang.Class<?> clazz,
java.lang.String fileName)
clazz - the class used for the resource lookupfileName - the name of the user agent stylesheet