×

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 ProgressBar

In the JavaFX application, in order to show the progress of work ProgressBar is used. It shows how much work is done. In order to use ProgressBar in JavaFX, javafx.scene.control.ProgressBar...

4 minutes read.

JavaFX RadioButton

In the JavaFX application, to get the user information in the form of choice from the user, a form is created using radio buttons that allow the user to select...

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

JavaFX Inner Shadow

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

4 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 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 ScrollBar

In the JavaFX application, in order to scroll over a range of values, ScrollBar is used. It is used to view long page contents. In order to use ScrollBar in...

4 minutes read.

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 TilePane

In the JavaFX application, in order to set TilePane as a layout, the TilePane class is used. The TilePane layout allows us to arrange the components in the same sized...

4 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 Gradient 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 gradient colors in these shapes using the...

7 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 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 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,...

5 minutes read.

JavaFX Path Transition

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

3 minutes read.

JavaFX Bubble Chart

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for this...

4 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 Box

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

4 minutes read.

JavaFX StackPane

In the JavaFX application, in order to set Stack Pane as a layout, the StackPane class is used. The StackPane layout allows us to arrange the components in the stack...

4 minutes read.

JavaFX Light Distant

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

4 minutes read.