Class Rating

  • All Implemented Interfaces:
    Styleable, EventTarget, Skinnable

    public class Rating
    extends Control
    A control for allowing users to provide a rating. This control supports 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:

    Screenshot of horizontal Rating

    To create a Rating control that looks like this is simple:

     
     final Rating rating = new Rating();

    This creates a default horizontal rating control.

    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:

    Screenshot of partial Rating

    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.

    • Constructor Detail

      • 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 the max argument, and a current rating as provided by the rating argument.
        Parameters:
        max - The maximum allowed rating value.
        rating - The current rating.
    • Method Detail

      • setRating

        public final void setRating​(double value)
        Sets the value of the property rating.
        Property description:
        The current rating value of the Rating control.
        Default value:
        3
      • getRating

        public final double getRating()
        Gets the value of the property rating.
        Property description:
        The current rating value of the Rating control.
        Default value:
        3
      • setMax

        public final void setMax​(int value)
        Sets the value of the property max.
        Property description:
        The maximum-allowed rating value.
        Default value:
        5
      • getMax

        public final int getMax()
        Gets the value of the property max.
        Property description:
        The maximum-allowed rating value.
        Default value:
        5
      • setOrientation

        public final void setOrientation​(Orientation value)
        Sets the value of the property orientation.
        Property description:
        The Orientation of the Rating - this can either be horizontal or vertical.
        Default value:
        Orientation.HORIZONTAL
      • getOrientation

        public final Orientation getOrientation()
        Gets the value of the property orientation.
        Property description:
        The Orientation of the Rating - this can either be horizontal or vertical.
        Default value:
        Orientation.HORIZONTAL
      • partialRatingProperty

        public final 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 wherever 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.
        Default value:
        false
        See Also:
        isPartialRating(), setPartialRating(boolean)
      • setPartialRating

        public final void setPartialRating​(boolean value)
        Sets the value of the property partialRating.
        Property description:
        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 wherever 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.
        Default value:
        false
      • isPartialRating

        public final boolean isPartialRating()
        Gets the value of the property partialRating.
        Property description:
        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 wherever 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.
        Default value:
        false
      • updateOnHoverProperty

        public final BooleanProperty updateOnHoverProperty()
        If true this allows for the 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.
        Default value:
        false
        See Also:
        isUpdateOnHover(), setUpdateOnHover(boolean)
      • setUpdateOnHover

        public final void setUpdateOnHover​(boolean value)
        Sets the value of the property updateOnHover.
        Property description:
        If true this allows for the 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.
        Default value:
        false
      • isUpdateOnHover

        public final boolean isUpdateOnHover()
        Gets the value of the property updateOnHover.
        Property description:
        If true this allows for the 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.
        Default value:
        false