ColorInput class is a part of JavaFX. It is used to create an effect which renders a rectangular region, filled with the given Color. It is equivalent to rendering a filled rectangle into an image and using an ImageInput effect, except that it is more convenient and potentially much more efficient. It is mainly passed into the other effects as an input.
Constructors of the class:
- ColorInput(): Creates a new instance of ColorInput with default parameters.
 - ColorInput(double x, double y, double width, double height, Paint paint): Creates a new instance of ColorInput with the specified x, y, width, height, and paint.
 
Commonly Used Methods:
| Method | Description | 
|---|---|
| getX() | Gets the value of the property x. | 
| getY() | Gets the value of the property y. | 
| setHeight(double value) | Sets the value of the property height | 
| setPaint(Paint value) | Sets the value of the property paint. | 
| setWidth(double value) | Sets the value of the property width. | 
| setX(double value) | Sets the value of the property x. | 
| setY(double value) | Sets the value of the property y. | 
| getHeight() | Gets the value of the property height. | 
| getPaint() | Gets the value of the property paint. | 
| getWidth() | Gets the value of the property width | 
- Java program to Demonstrate ColorInput class: In this program, ColorInput Effect is created and then we set the color, height, width, and coordinates of the region of ColorInput. A group object and scene object is created. A scene is added to the stage and then we set the title of the stage.
// Java program to Demonstrate ColorInput classimportjavafx.application.Application;importjavafx.scene.Group;importjavafx.scene.Scene;importjavafx.scene.effect.ColorInput;importjavafx.scene.paint.Color;importjavafx.scene.shape.Rectangle;importjavafx.stage.Stage;ÂÂpublicclassColorInputDemoextendsApplication {   Â// Main Method   Âpublicstaticvoidmain(String[] args)   Â{       Â// launch the application       Âlaunch(args);   Â}   Â// launch the application   Âpublicvoidstart(Stage primaryStage)throwsException   Â{       Â// Instantiating the ColorInput class       ÂColorInput color =newColorInput();       Â// set the color       Âcolor.setPaint(Color.GREEN);       Â// sets the height of the region of color input       Âcolor.setHeight(50);       Â// sets the width of the region of color input       Âcolor.setWidth(200);       Â// set the coordinates of the Colorinput       Âcolor.setX(90);       Âcolor.setY(140);       Â// create a rectangle       ÂRectangle rect =newRectangle();       Â// applying coloradjust effect       Ârect.setEffect(color);       Â// create a group object       ÂGroup root =newGroup();       Â// create a scene object       ÂScene scene =newScene(root,400,300);       Âroot.getChildren().add(rect);       Â// adding scene to the stage       ÂprimaryStage.setScene(scene);       Â// set title of the stage       ÂprimaryStage.setTitle("ColorInput Demo");       ÂprimaryStage.show();   Â}}Output:
 - Java program to apply ColorInput class to the created rectangle by clicking on the button using EventHandler: In this program, we first set the Height, Width, and coordinates of a rectangle and then create a rectangle of the same dimension. Now, create a Button and set the Layouts of the Button. Now, using EventHandler, first, instantiate a ColorInput class using proper dimension and then set ColorInput Effect to the Button. Create a group object and add Button and rectangle to it. Then Create a Scene and add it to the stage.
// Java program to apply ColorInput class toÂ// the created rectangle by clicking on theÂ// button using EventHandlerimportjavafx.application.Application;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.Group;importjavafx.scene.Scene;importjavafx.scene.control.Button;importjavafx.scene.effect.ColorInput;importjavafx.scene.paint.Color;importjavafx.scene.shape.Rectangle;importjavafx.stage.Stage;ÂÂpublicclassColorInputExampleextendsApplication {   Âpublicvoidstart(Stage stage)   Â{       Âdoublex =10;       Âdoubley =10;       Âdoublew =40;       Âdoubleh =180;       Â// Rectangle       ÂRectangle rect =newRectangle(x, y, w, h);       Ârect.setFill(Color.WHITE);       Ârect.setStrokeWidth(1);       Ârect.setStroke(Color.BLACK);       Â// Button       ÂButton button =newButton("Click To See the Effects!");       Â// set button layout coordinates       Âbutton.setLayoutX(100);       Âbutton.setLayoutY(30);       Âbutton.setPrefSize(250,150);       Âbutton.setOnAction(newEventHandler<ActionEvent>() {           Âpublicvoidhandle(ActionEvent event)           Â{               Â// instantiating the colorinput class               ÂColorInput colorInput =newColorInput(x, y,                                    Âw, h, Color.STEELBLUE);               Â// Setting ColorInput effect               Âbutton.setEffect(colorInput);           Â}       Â});       Â// create the Group object       ÂGroup root =newGroup();       Âroot.getChildren().addAll(button, rect);       ÂScene scene =newScene(root,450,300);       Âstage.setTitle("JavaFX ColorInput Effect");       Âstage.setScene(scene);       Âstage.show();   Â}   Â// Main Method   Âpublicstaticvoidmain(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/effect/ColorInput.html

                                    