JavaFX | CycleMethod Class Last Updated : 20 Sep, 2018 Comments Improve Suggest changes Like Article Like Report CycleMethod class is a part of JavaFX. CycleMethod defines the method to use when painting outside the gradient bounds. It contains 3 Enum Constants as follows: NO_CYCLE: Used to define the cycle method which uses terminal colors to fill the remaining area. REFLECT: Used to define the cycle method which reflects the gradient colors, start to end then end to start. REPEAT: Used to define the cycle method which repeats the gradient colors to fill the remaining area. Commonly Used Method: Method Explanation valueOf(String name) Returns the CycleMethod of the specified name. values() Returns an array which contains the values of Cyclemethod type. Below programs illustrate the use of the CycleMethod class: Java program to create a LinearGradient object, add stops to it, set the CycleMethod to repeat, set proportional to false and apply it to the rectangle: In this program we will create an array of Stop objects with their offset values ranging from 0 to 1. Then create a LinearGradient object with specified stops. Set the CycleMethod to repeat and set proportional to false. then create a circle with specified x, y positions, and radius and add the linear gradient to it. After that create a VBox and set the alignment of it. Add the circle to the vbox and add the vbox to the scene and add the scene to the stage and call the show() function to display the results. Java // Java program to create a LinearGradient object, // add stops to it, set the CycleMethod to repeat, // set proportional to false and apply it to the // rectangle import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.text.*; import javafx.geometry.*; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.scene.paint.*; public class CycleMethod_1 extends Application { // launch the application public void start(Stage stage) { try { // set title for the stage stage.setTitle("CycleMethod"); // create stops Stop[] stop = {new Stop(0, Color.RED), new Stop(1, Color.BLUE)}; // create a Linear gradient object LinearGradient linear_gradient = new LinearGradient(0, 0, 35, 0, false, CycleMethod.REPEAT, stop); // create a rectangle Rectangle rectangle = new Rectangle(100, 100, 100, 70); // set fill rectangle.setFill(linear_gradient); // create VBox VBox vbox = new VBox(rectangle); // ste Alignment vbox.setAlignment(Pos.CENTER); // create a scene Scene scene = new Scene(vbox, 400, 300); // set the scene stage.setScene(scene); stage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } } Output: Java program to create a LinearGradient object, add stops to it, set the CycleMethod to reflect, set proportional to false and apply it to the circle: In this program we will create an array of Stop objects with their offset values ranging from 0 to 1. Then create a LinearGradient object with specified stops. Set the CycleMethod to reflect and set proportional to false. Create a circle with specified x, y positions, and radius and add the linear gradient to it. Create a VBox and set the alignment of it. Add the circle to the vbox and add the vbox to the scene and add the scene to the stage. Call the show() function to display the results. Java // Java program to create a LinearGradient object, // add stops to it, set the CycleMethod to reflect, // set proportional to false and apply it to the // circle import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.text.*; import javafx.geometry.*; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.scene.paint.*; public class CycleMethod_2 extends Application { // launch the application public void start(Stage stage) { try { // set title for the stage stage.setTitle("CycleMethod"); // create stops Stop[] stop = {new Stop(0, Color.RED), new Stop(1, Color.BLUE)}; // create a Linear gradient object LinearGradient linear_gradient = new LinearGradient(0, 0, 35, 0, false, CycleMethod.REFLECT, stop); // create a rectangle Rectangle rectangle = new Rectangle(100, 100, 100, 70); // set fill rectangle.setFill(linear_gradient); // create VBox VBox vbox = new VBox(rectangle); // ste Alignment vbox.setAlignment(Pos.CENTER); // create a scene Scene scene = new Scene(vbox, 400, 300); // set the scene stage.setScene(scene); stage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } } Output: Java program to create LinearGradient object, add stops to it, set the CycleMethod to no cycle, set proportional to false and apply it to the rectangle: In this program we will create an array of Stop objects with their offset values ranging from 0 to 1. Create a LinearGradient object with specified stops. Set the CycleMethod to no cycle and set proportional to false. Then Create a circle with specified x, y positions, and radius, and add the linear gradient to it. Create a VBox and set the alignment of it. Now add the circle to the vbox and add the vbox to the scene and add the scene to the stage and call the show() function to display the results. Java // Java program to create LinearGradient object, // add stops to it, set the CycleMethod to no // cycle, set proportional to false and apply // it to the rectangle import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.text.*; import javafx.geometry.*; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.scene.paint.*; public class CycleMethod_3 extends Application { // launch the application public void start(Stage stage) { try { // set title for the stage stage.setTitle("CycleMethod"); // create stops Stop[] stop = {new Stop(0, Color.RED), new Stop(1, Color.BLUE)}; // create a Linear gradient object LinearGradient linear_gradient = new LinearGradient(0, 0, 35, 0, false, CycleMethod.NO_CYCLE, stop); // create a rectangle Rectangle rectangle = new Rectangle(100, 100, 100, 70); // set fill rectangle.setFill(linear_gradient); // create VBox VBox vbox = new VBox(rectangle); // ste Alignment vbox.setAlignment(Pos.CENTER); // create a scene Scene scene = new Scene(vbox, 400, 300); // set the scene stage.setScene(scene); stage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } } Output: Note: The above programs might not run in an online IDE please use an offline compiler. Reference: https://docs.oracle.com/javafx/2/api/javafx/scene/paint/CycleMethod.html Create Quiz Comment A andrew1234 Follow 0 Improve A andrew1234 Follow 0 Improve Article Tags : Java JavaFX Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like