JavaFX | Insets Class

14 Aug, 2018
Insets class is a part of JavaFX. Insets class stores the inside offsets for the four sides of the rectangular area. Insets class inherits java.lang.Object class.
Constructors of the class:
Insets(double a): Constructs a new Insets instance with same value for all four offsets.Insets(double top, double right, double bottom, double left): Constructs a new Insets instance with four different offsets.
Insets(double a): Constructs a new Insets instance with same value for all four offsets.
Insets(double top, double right, double bottom, double left): Constructs a new Insets instance with four different offsets.
Commonly Used Methods:
Below programs will illustrate the use of the Insets class:
Java program to create two insets object and display the contents: This program creates two Insets named insets_1 and insets_2. The insets are passed as arguments when the constructor is called. We will get four sides of the insets object using getTop(), getBottom(), getLeft(), getRight() function and display them.// Java program to create two insets // object and display the contentsimport javafx.geometry.Insets;  public class Insets_1 {      // Main Method    public static void main(String args[])    {                  // create two insets object        Insets insets_1 = new Insets(20.0f);        Insets insets_2 = new Insets(20.0f, 40.0f, 60.0f, 70.0f);          // display the insets        display(insets_1);        display(insets_2);    }          // display method    public static void display(Insets insets)    {        double left, right, bottom, top;          // get the insets        left = insets.getLeft();        right = insets.getRight();        bottom = insets.getBottom();        top = insets.getTop();          // display the insets        System.out.println("Insets of the object");        System.out.println("Left= " + left + ", Right = "                            + right + ", Bottom = " + bottom                            + ", Top = " + top);    }}Output:Insets of the object
Left = 20.0, Right = 20.0, Bottom = 20.0, Top = 20.0
Insets of the object
Left = 70.0, Right = 40.0, Bottom = 60.0, Top = 20.0
Java program to create three objects of insets and display its contents and check whether they are equal to each other or not: This program creates three Insets named insets_1, insets_2, and insets_3. The insets are passed as arguments when the constructor is called. We will get four sides of the insets object using getTop(), getBottom(), getLeft(), getRight() function and display them. We will also check whether the insets are equal to each other using the equals function.// Java program to create three objects of insets// and display its contents and check whether // they are equal to each other or notimport javafx.geometry.Insets;  public class Insets_2 {      // Main Method    public static void main(String args[])    {                  // create three insets objects        Insets insets_1 = new Insets(120.0f, 150.0f,                                      40.0f, 60.0f);                                                Insets insets_2 = new Insets(120.0f, 150.0f,                                        40.0f, 60.0f);                                                 Insets insets_3 = new Insets(200.0f, 120.0f,                                       60.0f, 40.0f);          // display the 3 insets        display(insets_1);        display(insets_2);        display(insets_3);          // check whether any insets is equal to other or not        System.out.println("Insets 1 equals Insets 2 = "                            + insets_1.equals(insets_2));                                     System.out.println("Insets 2 equals Insets 3 = "                             + insets_2.equals(insets_3));                                      System.out.println("Insets 3 equals Insets 1 = "                             + insets_3.equals(insets_1));    }      // display Method    public static void display(Insets insets)    {        double left, right, bottom, top;          // get the insets        left = insets.getLeft();        right = insets.getRight();        bottom = insets.getBottom();        top = insets.getTop();          // display the insets        System.out.println("Insets of the object");        System.out.println("Left= " + left + ", Right= "                           + right + ", Bottom= " + bottom                            + ", Top = " + top);    }}Output:Insets of the object
Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0
Insets of the object
Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0
Insets of the object
Left= 40.0, Right= 120.0, Bottom= 60.0, Top = 200.0
Insets 1 equals Insets 2 = true
Insets 2 equals Insets 3 = false
Insets 3 equals Insets 1 = false

Java program to create two insets object and display the contents: This program creates two Insets named insets_1 and insets_2. The insets are passed as arguments when the constructor is called. We will get four sides of the insets object using getTop(), getBottom(), getLeft(), getRight() function and display them.// Java program to create two insets // object and display the contentsimport javafx.geometry.Insets;  public class Insets_1 {      // Main Method    public static void main(String args[])    {                  // create two insets object        Insets insets_1 = new Insets(20.0f);        Insets insets_2 = new Insets(20.0f, 40.0f, 60.0f, 70.0f);          // display the insets        display(insets_1);        display(insets_2);    }          // display method    public static void display(Insets insets)    {        double left, right, bottom, top;          // get the insets        left = insets.getLeft();        right = insets.getRight();        bottom = insets.getBottom();        top = insets.getTop();          // display the insets        System.out.println("Insets of the object");        System.out.println("Left= " + left + ", Right = "                            + right + ", Bottom = " + bottom                            + ", Top = " + top);    }}Output:Insets of the object
Left = 20.0, Right = 20.0, Bottom = 20.0, Top = 20.0
Insets of the object
Left = 70.0, Right = 40.0, Bottom = 60.0, Top = 20.0

// Java program to create two insets // object and display the contentsimport javafx.geometry.Insets;  public class Insets_1 {      // Main Method    public static void main(String args[])    {                  // create two insets object        Insets insets_1 = new Insets(20.0f);        Insets insets_2 = new Insets(20.0f, 40.0f, 60.0f, 70.0f);          // display the insets        display(insets_1);        display(insets_2);    }          // display method    public static void display(Insets insets)    {        double left, right, bottom, top;          // get the insets        left = insets.getLeft();        right = insets.getRight();        bottom = insets.getBottom();        top = insets.getTop();          // display the insets        System.out.println("Insets of the object");        System.out.println("Left= " + left + ", Right = "                            + right + ", Bottom = " + bottom                            + ", Top = " + top);    }}
Output:
Insets of the object
Left = 20.0, Right = 20.0, Bottom = 20.0, Top = 20.0
Insets of the object
Left = 70.0, Right = 40.0, Bottom = 60.0, Top = 20.0

Java program to create three objects of insets and display its contents and check whether they are equal to each other or not: This program creates three Insets named insets_1, insets_2, and insets_3. The insets are passed as arguments when the constructor is called. We will get four sides of the insets object using getTop(), getBottom(), getLeft(), getRight() function and display them. We will also check whether the insets are equal to each other using the equals function.// Java program to create three objects of insets// and display its contents and check whether // they are equal to each other or notimport javafx.geometry.Insets;  public class Insets_2 {      // Main Method    public static void main(String args[])    {                  // create three insets objects        Insets insets_1 = new Insets(120.0f, 150.0f,                                      40.0f, 60.0f);                                                Insets insets_2 = new Insets(120.0f, 150.0f,                                        40.0f, 60.0f);                                                 Insets insets_3 = new Insets(200.0f, 120.0f,                                       60.0f, 40.0f);          // display the 3 insets        display(insets_1);        display(insets_2);        display(insets_3);          // check whether any insets is equal to other or not        System.out.println("Insets 1 equals Insets 2 = "                            + insets_1.equals(insets_2));                                     System.out.println("Insets 2 equals Insets 3 = "                             + insets_2.equals(insets_3));                                      System.out.println("Insets 3 equals Insets 1 = "                             + insets_3.equals(insets_1));    }      // display Method    public static void display(Insets insets)    {        double left, right, bottom, top;          // get the insets        left = insets.getLeft();        right = insets.getRight();        bottom = insets.getBottom();        top = insets.getTop();          // display the insets        System.out.println("Insets of the object");        System.out.println("Left= " + left + ", Right= "                           + right + ", Bottom= " + bottom                            + ", Top = " + top);    }}Output:Insets of the object
Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0
Insets of the object
Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0
Insets of the object
Left= 40.0, Right= 120.0, Bottom= 60.0, Top = 200.0
Insets 1 equals Insets 2 = true
Insets 2 equals Insets 3 = false
Insets 3 equals Insets 1 = false

// Java program to create three objects of insets// and display its contents and check whether // they are equal to each other or notimport javafx.geometry.Insets;  public class Insets_2 {      // Main Method    public static void main(String args[])    {                  // create three insets objects        Insets insets_1 = new Insets(120.0f, 150.0f,                                      40.0f, 60.0f);                                                Insets insets_2 = new Insets(120.0f, 150.0f,                                        40.0f, 60.0f);                                                 Insets insets_3 = new Insets(200.0f, 120.0f,                                       60.0f, 40.0f);          // display the 3 insets        display(insets_1);        display(insets_2);        display(insets_3);          // check whether any insets is equal to other or not        System.out.println("Insets 1 equals Insets 2 = "                            + insets_1.equals(insets_2));                                     System.out.println("Insets 2 equals Insets 3 = "                             + insets_2.equals(insets_3));                                      System.out.println("Insets 3 equals Insets 1 = "                             + insets_3.equals(insets_1));    }      // display Method    public static void display(Insets insets)    {        double left, right, bottom, top;          // get the insets        left = insets.getLeft();        right = insets.getRight();        bottom = insets.getBottom();        top = insets.getTop();          // display the insets        System.out.println("Insets of the object");        System.out.println("Left= " + left + ", Right= "                           + right + ", Bottom= " + bottom                            + ", Top = " + top);    }}
Output:
Insets of the object
Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0
Insets of the object
Left= 60.0, Right= 150.0, Bottom= 40.0, Top = 120.0
Insets of the object
Left= 40.0, Right= 120.0, Bottom= 60.0, Top = 200.0
Insets 1 equals Insets 2 = true
Insets 2 equals Insets 3 = false
Insets 3 equals Insets 1 = false

Note: The above programs might not run in an online IDE. Please use an offline compiler.
Reference: https://docs.oracle.com/javafx/2/api/javafx/geometry/Insets.html
JavaFX
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.