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.
| Modifier and Type | Field and Description |
|---|---|
| private IntegerProperty | |
| private ObjectProperty | |
| private BooleanProperty | |
| private DoubleProperty | |
| private BooleanProperty |
| Access | Constructor and Description |
|---|---|
| public | |
| 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 |
| Modifier and Type | Method and Description |
|---|---|
| protected Skin | createDefaultSkin()
Overrides javafx. Create a new instance of the default skin for this control. |
| public final int | |
| public final Orientation | |
| public final double | |
| public String | getUserAgentStylesheet()
Overrides javafx. An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. |
| public final boolean | |
| public final boolean | |
| public final IntegerProperty | |
| public final ObjectProperty | |
| public final BooleanProperty | |
| public final DoubleProperty | |
| public final void | |
| public final void | setOrientation(Orientation value)
Sets the |
| public final void | |
| public final void | |
| public final void | |
| public final BooleanProperty | updateOnHoverProperty()
If true this allows for the |
| max | back to summary |
|---|---|
| private IntegerProperty max | |
| orientation | back to summary |
|---|---|
| private ObjectProperty<Orientation> orientation | |
| partialRating | back to summary |
|---|---|
| private BooleanProperty partialRating | |
| rating | back to summary |
|---|---|
| private DoubleProperty rating | |
| updateOnHover | back to summary |
|---|---|
| private BooleanProperty updateOnHover | |
| Rating | back to summary |
|---|---|
| public Rating() Creates a default instance with a minimum rating of 0 and a maximum rating of 5. | |
| Rating | back 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.
| |
| Rating | back 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
| |
| createDefaultSkin | back to summary |
|---|---|
| protected Skin Overrides javafx. Doc from javafx. 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
| |
| getMax | back to summary |
|---|---|
| public final int getMax() Returns the maximum-allowed rating value. | |
| getOrientation | back to summary |
|---|---|
| public final Orientation getOrientation() Returns the | |
| getRating | back to summary |
|---|---|
| public final double getRating() Returns the current rating value. | |
| getUserAgentStylesheet | back to summary |
|---|---|
| public String getUserAgentStylesheet() Overrides javafx. Doc from javafx. 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.
For additional information about using CSS with the scene graph,
see the CSS Reference Guide.
| |
| isPartialRating | back to summary |
|---|---|
| public final boolean isPartialRating() Returns whether | |
| isUpdateOnHover | back to summary |
|---|---|
| public final boolean isUpdateOnHover() Returns whether | |
| maxProperty | back to summary |
|---|---|
| public final IntegerProperty maxProperty() The maximum-allowed rating value. | |
| orientationProperty | back to summary |
|---|---|
| public final ObjectProperty The | |
| partialRatingProperty | back 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. | |
| ratingProperty | back to summary |
|---|---|
| public final DoubleProperty ratingProperty() The current rating value. | |
| setMax | back to summary |
|---|---|
| public final void setMax(int value) Sets the maximum-allowed rating value. | |
| setOrientation | back to summary |
|---|---|
| public final void setOrientation(Orientation value) Sets the | |
| setPartialRating | back to summary |
|---|---|
| public final void setPartialRating(boolean value) Sets whether | |
| setRating | back to summary |
|---|---|
| public final void setRating(double value) Sets the current rating value. | |
| setUpdateOnHover | back to summary |
|---|---|
| public final void setUpdateOnHover(boolean value) Sets whether | |
| updateOnHoverProperty | back to summary |
|---|---|
| public final BooleanProperty updateOnHoverProperty() If true this allows for the | |