Top Description Fields Constructors Methods
org.controlsfx.control

public Class Rating

extends ControlsFXControl
Class Inheritance
Imports
impl.org.controlsfx.skin.RatingSkin, javafx.beans.property.BooleanProperty, .DoubleProperty, .IntegerProperty, .ObjectProperty, .SimpleBooleanProperty, .SimpleDoubleProperty, .SimpleIntegerProperty, .SimpleObjectProperty, javafx.geometry.Orientation, javafx.scene.control.Skin

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. 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:

Screenshot of vertical Rating

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.

Field Summary

Modifier and TypeField and Description
private IntegerProperty
private ObjectProperty<Orientation>
private BooleanProperty
private DoubleProperty
private BooleanProperty

Constructor Summary

AccessConstructor and Description
public
Rating()

Creates a default instance with a minimum rating of 0 and a maximum rating of 5.

public
Rating(int
The maximum allowed rating value.
max
)

Creates a default instance with a minimum rating of 0 and a maximum rating as provided by the argument.

public
Rating(int
The maximum allowed rating value.
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.

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public final int
getMax()

Returns the maximum-allowed rating value.

public final Orientation
getOrientation()

Returns the Orientation of the Rating - this can either be horizontal or vertical.

public final double
getRating()

Returns the current rating value.

public String
getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method.

public final boolean
isPartialRating()

Returns whether partial rating support is enabled or not.

public final boolean
isUpdateOnHover()

Returns whether update on hover support is enabled or not.

public final IntegerProperty
maxProperty()

The maximum-allowed rating value.

public final ObjectProperty<Orientation>
orientationProperty()

The Orientation of the Rating - this can either be horizontal or vertical.

public final BooleanProperty
partialRatingProperty()

If true this allows for users to set a rating as a floating point value.

public final DoubleProperty
ratingProperty()

The current rating value.

public final void
setMax(int value)

Sets the maximum-allowed rating value.

public final void
setOrientation(Orientation value)

Sets the Orientation of the Rating - this can either be horizontal or vertical.

public final void
setPartialRating(boolean value)

Sets whether partial rating support is enabled or not.

public final void
setRating(double value)

Sets the current rating value.

public final void
setUpdateOnHover(boolean value)

Sets whether update on hover support is enabled or not.

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.

Inherited from org.controlsfx.control.ControlsFXControl:
getUserAgentStylesheet

Field Detail

maxback to summary
private IntegerProperty max
orientationback to summary
private ObjectProperty<Orientation> orientation
partialRatingback to summary
private BooleanProperty partialRating
ratingback to summary
private DoubleProperty rating
updateOnHoverback to summary
private BooleanProperty updateOnHover

Constructor Detail

Ratingback to summary
public Rating()

Creates a default instance with a minimum rating of 0 and a maximum rating of 5.

Ratingback to summary
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:int

The maximum allowed rating value.

Ratingback to summary
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:int

The maximum allowed rating value.

Method Detail

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
getMaxback to summary
public final int getMax()

Returns the maximum-allowed rating value.

getOrientationback to summary
public final Orientation getOrientation()

Returns the Orientation of the Rating - this can either be horizontal or vertical.

getRatingback to summary
public final double getRating()

Returns the current rating value.

getUserAgentStylesheetback to summary
public String getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

Doc from javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. These styles are used in addition to whatever user-agent stylesheets are in use. This provides a mechanism for third parties to introduce styles for custom controls.

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.

Subclasses overriding this method should not assume any particular implementation approach as to the number and frequency with which it is called. For this reason, attempting any kind of dynamic implementation (i.e. returning different user agent stylesheet values) based on some state change is highly discouraged, as there is no guarantee when, or even if, this method will be called. Some JavaFX CSS implementations may choose to cache this response for an indefinite period of time, and therefore there should be no expectation around when this method is called.



package com.example.javafx.app;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {

    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
Annotations
@Override
isPartialRatingback to summary
public final boolean isPartialRating()

Returns whether partial rating support is enabled or not.

isUpdateOnHoverback to summary
public final boolean isUpdateOnHover()

Returns whether update on hover support is enabled or not.

maxPropertyback to summary
public final IntegerProperty maxProperty()

The maximum-allowed rating value.

orientationPropertyback to summary
public final ObjectProperty<Orientation> orientationProperty()

The Orientation of the Rating - this can either be horizontal or vertical.

partialRatingPropertyback to summary
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 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.

ratingPropertyback to summary
public final DoubleProperty ratingProperty()

The current rating value.

setMaxback to summary
public final void setMax(int value)

Sets the maximum-allowed rating value.

setOrientationback to summary
public final void setOrientation(Orientation value)

Sets the Orientation of the Rating - this can either be horizontal or vertical.

setPartialRatingback to summary
public final void setPartialRating(boolean value)

Sets whether partial rating support is enabled or not.

setRatingback to summary
public final void setRating(double value)

Sets the current rating value.

setUpdateOnHoverback to summary
public final void setUpdateOnHover(boolean value)

Sets whether update on hover support is enabled or not.

updateOnHoverPropertyback to summary
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.