×

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation, brightness, input, and contrast. All methods needed for this purpose are present in the javafx.scene.effect.ColorAdjust class.

Properties and corresponding methods to create Color Adjust Effect :

1. hue

This property is of double type. It is used to represent the various adjustment user had made in the hue of the color and the setHue( double huevalue ) method is used to set it.

2. contrast

This property is of double type. It is used to represent the various adjustment user had made in the contrast of the color and the setContrast( double contrastvalue) method is used to set it.

3. brightness

This property is of double type. It is used to represent the various adjustment user had made in the brightness of the color and the setBrightness( double brightnessvalue ) method is used to set it.

4. saturation

This property is of double type. It is used to represent the various adjustment user had made in the saturation of the color and the setSaturation( double saturationvalue ) method is used to set it.

5. input

This property is of double type. It is used to represent the value which is the input for the user and the setInput( double inputvalue ) method is used to set it.

JavaFX Effect – Color Adjust

Example:

import javafx.application.Application;  
import javafx.scene.paint.Color;  
import javafx.scene.shape.Rectangle;  
import javafx.scene.text.Font;  
import javafx.scene.text.FontPosture;  
import javafx.scene.text.FontWeight;  
import javafx.scene.text.Text;  
import javafx.stage.Stage;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Image newimage = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");
        
        ImageView newimageView = new ImageView(newimage); 
        
        newimageView.setX(140);  
        newimageView.setY(90); 
        
        newimageView.setFitHeight(200); 
        newimageView.setFitWidth(400); 
        
        newimageView.setPreserveRatio(true); 
      
        ColorAdjust newAdjust = new ColorAdjust(); 
        
        newAdjust.setContrast(0.3);     
        
        newAdjust.setHue(-0.05);     
        
        newAdjust.setBrightness(0.9);  
        
        newAdjust.setSaturation(0.8);   
         
        newimageView.setEffect(newAdjust);    
           
        Group root = new Group(newimageView);  
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Color Adjust Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Color Adjust Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.scene.text.Font, javafx.scene.text.FontPosture, javafx.scene.text.FontWeight, javafx.scene.text.Text, javafx.stage.Stage, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorAdjust, javafx.scene.image.Image, javafx.scene.image.ImageView.

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 an icon with a color adjust effect, a Group object is created which is then passed to the Scene class object.

The Home icon image is imported and the color adjust constructor is created and various properties are set using setters and using setEffect() method, the color adjust effect is applied on the Home icon.

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 Adjust Effect example”. Also, it displays a home icon with specified color adjust the effect on it.

JavaFX Effect – Color Adjust

JavaFX Effect – Images with and without Color Adjust Effect

Example:

import javafx.application.Application;  
import javafx.scene.paint.Color;  
import javafx.scene.shape.Rectangle;  
import javafx.scene.text.Font;  
import javafx.scene.text.FontPosture;  
import javafx.scene.text.FontWeight;  
import javafx.scene.text.Text;  
import javafx.stage.Stage;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Image newimage = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");
        
        ImageView newimageView = new ImageView(newimage); 
Image newimage2 = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");
        
        ImageView newimageView2 = new ImageView(newimage); 
        
        newimageView.setX(140);  
        newimageView.setY(90); 
        newimageView2.setX(440);  
        newimageView2.setY(90); 
        
        newimageView.setFitHeight(200); 
        newimageView.setFitWidth(400); 
        newimageView2.setFitHeight(200); 
        newimageView2.setFitWidth(400); 
        
        newimageView.setPreserveRatio(true); 
        newimageView2.setPreserveRatio(true); 


        ColorAdjust newAdjust = new ColorAdjust(); 
        
        newAdjust.setContrast(0.3);     
        
        newAdjust.setHue(-0.05);     
        
        newAdjust.setBrightness(0.9);  
        
        newAdjust.setSaturation(0.8);   
         
        newimageView.setEffect(newAdjust);    
           
        Group root = new Group(newimageView,newimageView2);  
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Color Adjust Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Image with and without Color Adjust Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.scene.text.Font, javafx.scene.text.FontPosture, javafx.scene.text.FontWeight, javafx.scene.text.Text, javafx.stage.Stage, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorAdjust, javafx.scene.image.Image, javafx.scene.image.ImageView.

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 an icon with and without color adjust effect, a Group object is created which is then passed to the Scene class object.

The Home icon image is imported and the color adjust constructor is created and various properties are set using setters and using setEffect() method, the color adjust effect is applied on one Home icon and the other is kept as it is for identifying 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 Adjust Effect example”. Also, it displays a one home icon with color adjust effect and the other without any color adjust effect.

JavaFX Effect – Color Adjust

Related Topics

JavaFX Line

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

3 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 Pie Chart

In the JavaFX application, in order to create Pie Chart, the PieChart class is used. The Pie Chart allows us to plot data along with the sectors of the circle....

3 minutes read.

JavaFX File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

4 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

4 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 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 Label

The UI Control Label in a JavaFX is used to display the simple text. To use Label in JavaFX application javafx.scene.control.The label class is used. We can place Labels on...

3 minutes read.

JavaFX Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the colors in these shapes using the setFill()...

6 minutes read.

JavaFX Shear

In the JavaFX application, in order to apply various shear effect, we use this class. It has the ability to shear the given object along the x or y axis....

3 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 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 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 Shadow

In the JavaFX application, in order to apply various Shadow effect from a single source, we use this class. It has the ability to create the shadow of the given...

3 minutes read.

JavaFX HBox

In the JavaFX application, in order to set HBox as a layout, the HBox class is used. The HBox layout allows us to arrange the components in one row. All...

3 minutes read.

JavaFX Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX Blend

In the JavaFX application, in order to apply various blend effect, we use Blend class. It has the ability to blend the colors of the shape. All methods needed for...

4 minutes read.

JavaFX Glow

In the JavaFX application, in order to apply various glow effect, we use Glow class. It has the ability to glow the colors of the shape. All methods needed for...

4 minutes read.