Create RadialGradient for an Ellipse
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.RadialGradient;
import javafx.scene.paint.RadialGradientBuilder;
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);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Colors");
Group root = new Group();
Scene scene = new Scene(root, 350, 300, Color.WHITE);
Ellipse ellipse = new Ellipse(100, 50 + 70/2, 50, 70/2);
RadialGradient gradient1 = RadialGradientBuilder.create()
.focusAngle(0)
.focusDistance(.1)
.centerX(80)
.centerY(45)
.radius(120)
.proportional(false)
.cycleMethod(CycleMethod.NO_CYCLE)
.stops(new Stop(0, Color.RED), new Stop(1, Color.BLACK))
.build();
ellipse.setFill(gradient1);
root.getChildren().add(ellipse);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Related examples in the same category