JavaFX LinearGradient create

Description

JavaFX LinearGradient create

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.LinearGradientBuilder;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;

public class Main extends Application {

   public static void main(String[] args) {
      Application.launch(args);/*from   ww w .j a v a2  s  . c  o m*/
   }

   @Override
   public void start(Stage primaryStage) {
      primaryStage.setTitle("java2s.com");
      Group root = new Group();
      Scene scene = new Scene(root, 300, 250, Color.WHITE);

      Ellipse bigCircle = new Ellipse();
      bigCircle.setCenterX(100);
      bigCircle.setCenterY(100);
      bigCircle.setRadiusX(50);
      bigCircle.setRadiusY(75 / 2);

      bigCircle.setStrokeWidth(3);
      bigCircle.setStroke(Color.BLACK);


      LinearGradient linearGrad = LinearGradientBuilder.create()
            .startX(100)
            .startY(100)
            .endX(50)
            .endY(50)
            .proportional(false)
            .cycleMethod(CycleMethod.NO_CYCLE)
            .stops( new Stop(0.1f, Color.rgb(255, 200, 0, .784)),
                    new Stop(1.0f, Color.rgb(0, 0, 0, .784)))
            .build();
      bigCircle.setFill(linearGrad);
      root.getChildren().add(bigCircle);

      primaryStage.setScene(scene);

      primaryStage.show();
   }
}



PreviousNext

Related