Table of contents
1.
Introduction
2.
ColorInput Class
2.1.
Constructors
2.2.
Properties and their Corresponding Setter Methods
3.
Implementation
4.
Frequently Asked Questions
4.1.
What is JavaFX used for?
4.2.
What are constructors in JFX?
4.3.
What are the three components of JavaFX?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

JavaFX ColorInput

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

When we start creating art or graphics on a computer, the most basic thing that we do is draw and add color. Well, you can draw anything you want but coloring is the most fun part! Isn’t it!? Well to color your creation, we hereby introduce you to the Java FX colorinput class, which can easily help you color any of your creations. Before going further, let’s know a little about JavaFX.

JavaFX is a Java library for creating rich client applications. It provides an API for creating graphical user interface (GUI) applications that can run on almost any device that supports Java. 

This blog will discuss the ColorInput class present in the JavaFX framework. We will also examine the types of constructors and methods present in the ColorInput class. Along with its implementation, so let’s get started.

ColorInput Class

JavaFX includes the ColorInput class. The ColorInput class is used in the JavaFX application to apply various color input effects. It can fill the specified shape with a given color input effect. The javafx.scene.effect package contains all of the methods required for this purpose.

It's used to make an effect that draws a rectangular region filled with the specified color. It's the same as rendering a filled rectangle into an image and applying an ImageInput effect, except it's much more convenient and potentially much more efficient. It is primarily used as an input to the other effects.

Now we’ll discuss the different constructors present in this class using which we can initiate the class.

Constructors

There are two different types of constructors available in the colorinput class:

  1. ColorInput(): Creates a new ColorInput instance with the default parameters.
  2. ColorInput(double x, double y, double width, double height, Paint paint): Creates a new ColorInput instance with the specified x, y, width, height, and paint.

Properties and their Corresponding Setter Methods

Javafx.scene.effect.ColorInput class properties and their setter methods are described in the table below.

properties and methods

Implementation

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 ColorInput extends Application {


  public static void main(String[] args)
  {
    launch(args);
  }


  public void start(Stage primaryStage) throws Exception
  {


    ColorInput color = new ColorInput();


    // setting the color
    color.setPaint(Color.RED);


    // setting the height of the region of color input
    color.setHeight(50);


    // setting the width of the region of color input
    color.setWidth(200);


    // setting the coordinates of the Colorinput
    color.setX(90);
    color.setY(140);


    // creating a rectangle
    Rectangle rect = new Rectangle();


    // applying coloradjust effect
    rect.setEffect(color);


    // creating a group object
    Group root = new Group();


    // creating a scene object
    Scene scene = new Scene(root, 400, 300);


    root.getChildren().add(rect);


    // adding scene to the stage
    primaryStage.setScene(scene);


    // setting title of the stage
    primaryStage.setTitle("ColorInput");


    primaryStage.show();
  }
}

 

Output

output

Frequently Asked Questions

What is JavaFX used for?

Rich client applications can be created, tested, debugged, and deployed across various platforms using JavaFX, a set of graphics and media packages.

What are constructors in JFX?

A constructor in JFX is a block of code that is similar to a method. It is called when a new instance of the class is created.

What are the three components of JavaFX?

Stage, Scene, and Nodes are the three main components of a JavaFX application.

Conclusion

In this article, we have extensively discussed the ColorInput class present inside JavaFX Framework. We have seen different constructors initialized in ColorInput class. Also, we have seen different methods available inside the class along with the implementation.

If you think this blog has helped you enhance your knowledge about JavaFx ColorInput and if you would like to learn more, check out our articles JavaFXJavaFX HBoxJavaFX FileChooserJavaFX VBoxJavaFX Fade TransitionJavaFX Sequential Transition, and many more on our Website.

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 competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

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

Happy Learning!

Live masterclass