JavaFX - Rating ControlsFX

Maven ControlsFX

<dependencies>
   <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-controls</artifactId>
      <version>20.0.1</version>
   </dependency>
   <dependency>
      <groupId>org.controlsfx</groupId>
      <artifactId>controlsfx</artifactId>
      <version>11.1.2</version>
   </dependency>
</dependencies>

L'élément Rating de ControlsFX

import org.controlsfx.control.Rating;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class App extends Application {

  private static final int MAX_RATING = 5;
  private static final int DEFAULT_RATING = 4;

  public static void main(String[] args) {
    launch();
  }

  @Override
  public void start(Stage stage) {

    /* L'élément rating */
    var rating = new Rating(MAX_RATING, DEFAULT_RATING);
    /* Pour avoir demi-étoile mettre à true */
    rating.setPartialRating(false);

    var ratingLabel = new Label();

    /* Listener pour la note */
    rating.ratingProperty().addListener((obsRating, oldRating, newRating) -> {
      ratingLabel.setText("Nouvelle note : " + newRating + " étoile(s)");
    });

    var scene = new Scene(new VBox(rating, ratingLabel), 250, 150);
    stage.setScene(scene);
    stage.show();
  }

}

Commentaires