JavaFX Tutorial Index

JavaFX Tutorial JavaFX Installation JavaFX Application Structure JavaFX Architecture

JavaFX Applications Charts

JavaFX Bar Chart JavaFX Bubble Chart JavaFX Pie Chart JavaFX Scatter Chart JavaFX Area Chart JavaFX Line Chart

JavaFX 2D Shapes

JavaFX Arc JavaFX Circle JavaFX Ellipse JavaFX Line JavaFX Polygon JavaFX Rectangle JavaFX Color JavaFX Gradient Color

JavaFX 3D Shapes

JavaFX Box JavaFX Cylinder JavaFX Sphere

JavaFX Animations

JavaFX Rotate Transition JavaFX Translate Transition JavaFX Fade Transition JavaFX Fill Transition JavaFX Parallel Transition JavaFX Path Transition JavaFX Pause Transition JavaFX Scale Transition JavaFX Sequential Transition JavaFX Stroke Transition

JavaFX CSS

JavaFX ID Selector JavaFX Inline Styles JavaFX Selectors

JavaFX Effect

JavaFX Blend JavaFX Bloom JavaFX Color Adjust JavaFX Color Input JavaFX Drop Shadow JavaFX Gaussian Blur JavaFX Glow JavaFX Image Input JavaFX Inner Shadow JavaFX Light Distant JavaFX Light Point JavaFX Light Spot JavaFX Lighting JavaFX Motion Blur JavaFX Reflection JavaFX Shadow

JavaFX Layouts

JavaFX Layouts JavaFX BorderPane JavaFX GridPane JavaFX StackPane JavaFX HBox JavaFX TilePane

JavaFX Event Handling

JavaFX Event Handling JavaFX Event Filters JavaFX Convenience Methods

JavaFX Transformation

JavaFX Transformation JavaFX Scaling JavaFX Rotation JavaFX Translation JavaFX Shear

JavaFX UI

JavaFX Menu JavaFX Button JavaFX Button Styling JavaFX CheckBox JavaFX File Chooser JavaFX HyperLink JavaFX Label JavaFX UI Controls JavaFX PasswordField JavaFX ProgressBar JavaFX RadioButton JavaFX ScrollBar JavaFX Slider JavaFX TextField

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