LinearGradient and stop : LinearGradient « JavaFX « Java






LinearGradient and stop

 

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.Stop;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class Main extends Application {

  @Override
  public void start(Stage stage) {
    final Group group = new Group();
    Scene scene = new Scene(group, 300, 150);
    stage.setScene(scene);
    stage.setTitle("Sample");

    Stop[] stops = { new Stop(0, Color.WHITE), new Stop(1, Color.BLACK)};
    LinearGradient lg = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops);
    Rectangle r = new Rectangle(20,20,200,200);
    r.setFill(lg);
   

    group.getChildren().add(r);
    stage.show();
  }

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

   
  








Related examples in the same category

1.Add LinearGradient to Rectangle