×

JavaFX Color Input

In the JavaFX application, in order to apply various color input effect, we use the ColorInput class. It has the ability to fill the specified shape with a given color input effect. All methods needed for this purpose are present in the javafx.scene.effect.ColorInput class.

Properties and corresponding methods to create Color Input Effect :

1. x

This property is of double type. It is used to represent the x top left coordinate of the shape and the setX( double xvalue ) method is used to set it.

2. y

This property is of double type. It is used to represent the y top left coordinate of the shape and the setY( double yvalue) method is used to set it.

3. width

This property is of double type. It is used to represent the width of the specified shape and the setWidth( double widthvalue ) method is used to set it.

4. height

This property is of double type. It is used to represent the height of the specified shape and the setHeight( double heightvalue ) method is used to set it.

5. paint

This property is of paint type. It is used to represent the paint property that is to be filled in the given shape and the setPaint( Paint paintvalue ) method is used to set it.

JavaFX Effect – Color Input

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ColorInput;  
import javafx.scene.paint.Color;  
import javafx.scene.shape.Rectangle;  
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    ColorInput newcolor = new ColorInput();  
    newcolor.setPaint(Color.BLUE);        
    newcolor.setHeight(200);  
    newcolor.setWidth(200);  
    newcolor.setX(140);  
    newcolor.setY(90);  
        Rectangle rect = new Rectangle();  
        rect.setEffect(newcolor);    
           
        Group root = new Group(rect);  
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Color Input Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Color Input Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorInput, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.stage.Stage.

Then we have created one class named EffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a rectangle filled with color input effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and the color input constructor is created, various properties are set using the setters, and the setEffect() method is used to set the color input effect on the rectangle.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Color Input Effect example”. Also, it displays a rectangle with a color input effect on it.

JavaFX Effect – Color Input

JavaFX Effect – Rectangles with and without Color Input Effect Example :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ColorInput;  
import javafx.scene.paint.Color;  
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class SliderUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    ColorInput newcolor = new ColorInput();  
    newcolor.setPaint(Color.BROWN);        
    newcolor.setHeight(200);  
    newcolor.setWidth(200);  
    newcolor.setX(140);  
    newcolor.setY(90);  
        Rectangle rect = new Rectangle();  
        rect.setEffect(newcolor);    
        Rectangle rect2 = new Rectangle();  
         rect2.setX(380);
         rect2.setY(90);;
      rect2.setHeight(200);  
    rect2.setWidth(200);  
           
    Text text1 = new Text();  
        Text text2 = new Text();  
        text1.setText("ColorInput Effect Applied");  
        text2.setText("ColorInput Effect Not Applied");  
        text1.setX(150);  
        text1.setY(350);  
        text2.setX(405);  
        text2.setY(350);  
        text1.setFill(Color.RED);  
        text2.setFill(Color.RED);  
        text1.setStroke(Color.BLACK);  
        text2.setStroke(Color.BLACK);  
        text1.setStrokeWidth(0.2);  
        text2.setStrokeWidth(0.2);  
   
        Group root = new Group(rect,rect2,text1,text2);  
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Color Input Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Rectangle with and without Color Input Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorInput, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.stage.Stage.

Then we have created one class named EffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a rectangle filled with and without color input effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and the color input constructor is created, various properties are set using the setters, and the setEffect() method is used to set the color input effect on one rectangle and one without color input effect to identify the difference.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Color Input Effect example”. Also, it displays a rectangle with and without color input effect on it.

JavaFX Effect – Color Input

Related Topics

JavaFX Inline Styles

In the JavaFX application, in order to apply various Inline css effect we will use the various css classes available in the JavaFX. It is used to apply the various...

4 minutes read.

JavaFX Reflection

In the JavaFX application, in order to apply various reflection effect, we use this class. It has the ability to create the reflection of the given object. This effect adds...

4 minutes read.

JavaFX Sphere

In the JavaFX application, in order to draw a Sphere, the Sphere class is used. The Sphere allows us to form a 3D shape having circular faces. All methods needed...

4 minutes read.

JavaFX GridPane

In the JavaFX application, in order to set Grid Pane as a layout, the GridPane class is used. The GridPane layout allows us to arrange the components in the form...

4 minutes read.

JavaFX Pause Transition

In the JavaFX application, in order to generate the pause transition, we have to apply pause transition on any particular shape. It has the ability to take a particular pause...

4 minutes read.

JavaFX Area Chart

In the JavaFX application, in order to create Area Chart, the AreaChart class is used. The Area Chart allows us to plot data along the XY plane. All methods needed...

3 minutes read.

JavaFX Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for...

5 minutes read.

JavaFX Architecture

JavaFX architecture consists of many built-in components such as JavaFX public API, Scene Graph, Quantum Toolkit, Prism, Glass windowing toolkit, web view, media engines. These components help to develop rich...

3 minutes read.

JavaFX Translate Transition

In the JavaFX application, in order to generate the translate transition, we have to apply translate transition on any particular shape. It has the ability to translate the shape along...

3 minutes read.

JavaFX Scaling

In the JavaFX application, in order to apply various Scaling effects, we use this class. It has the ability to change the size of the given object. All methods needed...

5 minutes read.

JavaFX CheckBox

In the JavaFX application, to get the user information in the form of choices from the user, a form is created using checkboxes that allow the user to select two...

4 minutes read.

JavaFX Layouts

Layouts in the JavaFX application are treated as a container for different UI elements such as Button, Label, TextArea, etc. Layouts are used as parent container. The layout is used...

3 minutes read.

JavaFX Scale Transition

In the JavaFX application, in order to generate the scale transition, we have to apply scale transition on any particular shape. It has the ability to scale the shape along...

4 minutes read.

JavaFX Ellipse

In the JavaFX application, in order to draw an Ellipse, the Ellipse class is used. The Ellipse allows us to join any points in the space to draw the unique...

7 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX Translation

In the JavaFX application, in order to apply various Translate effect, we use this class. It has the ability to Translate the given object according to the specified parameter. All...

4 minutes read.

JavaFX Cylinder

In the JavaFX application, in order to draw a Cylinder, the Cylinder class is used. The Cylinder allows us to form a 3D shape having rectangular faces and a straight...

4 minutes read.

JavaFX Button

The button is one of the UI control present in the JavaFX. The javafx.scene.control.Button class is used for creating a button in javafx example. It is also possible to create...

5 minutes read.