Metro Style Rating Control for Java (JMetro)
Join the DZone community and get the full member experience.
Join For Freethe rating control is one of windows first class citizens, it’s available in its control library, it allows a user to rate something from 0 to an x value. given the importance of today’s social interaction it’s no wonder it has gained the status of a library control.
controlsfx is a third party library of controls for javafx, it complements the standard library with some more useful controls and functionality which are not available straight from javafx’s standard library. one of the controls present is the rating control which i opportunely took the chance to use and style the metro way through css.
in its default style, this control uses raster image files. one for the “selected” state:
and one for the “unselected” state:
using this css code for the “unselected” state:
.rating > .container > .button { -fx-background-image: url("unselected-star.png"); }
and this for the “selected” state:
.rating > .container > .button.strong { -fx-background-image: url("selected-star.png"); }
“.strong” is the style class given to “selected” star buttons.
for jmetro i wanted to use vector based images instead of raster ones. to that effect i used the css property: “-fx-shape” and set the “-fx-background-image” to null which is the same as removing it.
advantages of using vector based images:
- you can make them as big as you want without losing image quality
- fill color, stroke color, etc can be tweaked through css
- it occupies less space
by this, i’m not saying that vector based images should be used every time, there are certainly use cases where raster based ones are more convenient, specially at lower sizes.
in conclusion, you can do some really powerful stuff this way using only javafx css code. you can either rely on the usage of raster based images or vector based ones.
Published at DZone with permission of Pedro Duque Vieira, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
-
Integrating AWS With Salesforce Using Terraform
-
Authorization: Get It Done Right, Get It Done Early
-
Introduction To Git
Comments