Star Rating Panel for Java Swing

posted on: Tuesday, 31st of August 2010

We couldn't find a good star rating component for Java Swing, so we rolled our own. The star rating component displays the current current rating (yellow stars), as well as a "selected" rating (reddish stars). The "selected" rating can be changed by a user. If the "selected" rating is changed, all the listeners will be notified of the change.

Star Rating

Example (5 stars, 3.78 average rating, 3 stars initial selection):

StarRater starRater = new StarRater(5, 3.61, 3);
starRater.addStarListener(new StarRater.StarListener() {
  public void handleSelection(int selection) {
    // a new number of stars has been selected
    do something...
add(starRater);   // add the component to the container...

The star rating component will initially be used to rate maps in Age of Conquest.

Here is the download for both source code & star images (Photoshop). Note that we included the star images as byte array in the source code for your convenience. You are obviously free to use your own as well. Please consider both source code as well as images in the Public Domain. If you would like to credit us for the work that's great, otherwise, no problem either:

Download: Star Rater Component (Swing) + Star Images (Photoshop)