Table of contents
1.
Introduction
2.
JavaFX ColorAdjust
2.1.
Constructor
2.2.
Properties
2.3.
Implementation
3.
Frequently Asked Questions
3.1.
What is a JavaFX control?
3.2.
What is the basic structure of JavaFX?
3.3.
Is JavaFX a programming language?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

JavaFX ColorAdjust

Author Sagar Mishra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

JavaFX is a Java framework and GUI toolkit. It creates and supports Rich Internet, web, and desktop apps. The main motive for implementing JavaFX is that programs created with it can run on many platforms. Desktops, the web, mobile phones, TVs, tablets, and operating systems like Windows, Linux, iOS, and Android are some samples.

In this article, we will learn the features of JavaFX ColorAdjust, like constructors and some properties. We will also discuss the working example of JavaFX ColorAdjust code in the end. So, let's dive into the article without wasting time.

JavaFX ColorAdjust

JavaFX enables us to enhance the look of an image By altering the hue, saturation, brightness, and contrast of the image's color. The javafx.scene.effect class can be applied to the node using a variety of properties and methods held in the ColorAdjust object.

Here is an example of JavaFX ColorAdjust to set hoe, brightness, contrast, and many more on your own.

ColorAdjust colorAdjust = new ColorAdjust();
 colorAdjust.setContrast(0.2);
 colorAdjust.setHue(-0.06);
 colorAdjust.setBrightness(0.2);
 colorAdjust.setSaturation(0.1);


 Image image = new Image("car.jpg");
 ImageView imageView = new ImageView(image);
 imageView.setFitWidth(150);
 imageView.setPreserveRatio(true);
 imageView.setEffect(colorAdjust);

Constructor

The two constructors present in JavaFX ColorAdjust are given below:

  1. public ColorAdjust(): It creates the new instance of ColorAdjust with the default parameters.
     
  2. public ColorAdjust(double hue, double saturation, double brightness, double contrast): It creates a new instance of the ColorAdjust with the fixed parameters.

Properties

properties of JavaFX ColorAdjust

Implementation

The ColorAdjust Effect has been applied to an image with many features in the example below. The output displays a comparison between the affected image and the original image.

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class ColorAdjustEffectExample extends Application {

   @Override
   public void start(Stage stage) {

       String imageUrl = "https://www.codingninjas.com/images/logo.png";
       Image image = new Image(imageUrl);

       ImageView imageView1 = new ImageView(image);
       imageView1.setX(100);
       imageView1.setY(20);

       ImageView imageView2 = new ImageView(image);

       imageView2.setX(100);
       imageView2.setY(170);

       // Create the ColorAdjust
       ColorAdjust colorAdjust = new ColorAdjust();

       // Setting the contrast value
       colorAdjust.setContrast(0.3);

       // Setting the hue value
       colorAdjust.setHue(-0.05);

       // Setting the brightness value
       colorAdjust.setBrightness(0.5);

       // Setting the saturation value
       colorAdjust.setSaturation(0.7);

       // Applying ColorAdjust effect to the ImageView node
       imageView2.setEffect(colorAdjust);

       Group root = new Group(imageView1, imageView2);

       Scene scene = new Scene(root, 450, 320);
       stage.setTitle("JavaFX ColorAdjust Effect");
       stage.setScene(scene);
       stage.show();
   }

   public static void main(String args[]) {
       launch(args);
   }
}
You can also try this code with Online Java Compiler
Run Code

 

Output

ouput image

Frequently Asked Questions

What is a JavaFX control?

In a JavaFX application, JavaFX controls are JavaFX features that offer some control capacity. A few examples of JavaFX Control are a button, radio, table, tree, etc. The control must be associated with the scene graph of some Scene object to display it.

What is the basic structure of JavaFX?

The three main parts of a JavaFX application are ranked hierarchically into Stage, Scene, and nodes. Importing the JavaFX application is required. Every JavaFX application has an application class.

Is JavaFX a programming language?

The JavaFX Script language, commonly known as JavaFX, is a declarative scripting language with statically typed data. The declarative syntax, list comprehensions, and incremental dependency-based evaluation are all first-class features.

Conclusion

We have discussed the topic ColorAdjust Class present inside JavaFX Framework in this blog. We have seen different constructors that initialize the ColorAdjust object. Also, we have seen other properties available inside the class, along with the working code.

We hope this blog has helped you enhance your knowledge of JavaFX ColorAdjust. If you want to learn more, check out our blogs JavaFX ShadowJavaFX HBoxJavaFX ArcJavaFX Stroke Transition, and many more on our platform Coding Ninjas Studio.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your skill in coding, you may check out the mock test series. And partake in the contests hosted on Coding Ninjas Studio! 

But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement practices.

However, you may consider our paid courses to give your career an edge over others!

Happy Learning!

thankyou

Live masterclass