×

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 tiles according to specified boundries. All methods needed for this purpose are present in the javafx.scene.layout.TilePane class.

The constructor of TilePane layout:

1. TilePane():

It is used to create an empty tile pane layout with uniformly sized tiles.

2. TilePane( Orientation o ):

It is used to create an empty tile pane layout with uniform-sized tiles and specified orientation.

Methods to set TilePane as a layout:

1. setAlignment(pos v)

This property of the TilePane class allows us to set the alignment of the layout.

2. setOrientation(Orientation v)

This property of TilePane class is used to set the orientation of the TilePane.

3. setVgap(Double v)

This property of the TilePane class is used to set vertical space between two nodes in the TilePane.

4. setHgap(Double v)

This property of the TilePane class is used to set horizontal space between two nodes in the TilePane.

Layouts in JavaFX applications- Simple Tile Pane

Example:

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;


public class TilePaneUI extends Application 
{  


    @Override  
    public void start (Stage primaryStage) throws Exception 
    {  
    Button[] buttons = new Button[] { 
             new Button (" New "), 
             new Button ("  Open "), 
             new Button (" Save "), 
             new Button (" Cut "), 
             new Button (" Copy "), 
             new Button (" Paste "), 
             new Button (" Exit ")  
          };   
          TilePane Pane = new TilePane();   
           
          Pane.setOrientation(Orientation.HORIZONTAL); 
           
          Pane.setTileAlignment(Pos.CENTER_LEFT); 
           
          
          ObservableList list = Pane.getChildren(); 
           
          list.addAll(buttons);
      
          Scene scene = new Scene(Pane,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle(" JavaFX Layout - Tile Pane Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the TilePane with the uniformed size tiles in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.control.Button,  javafx.scene.layout.TilePane, javafx.collections.ObservableList, javafx.geometry.Orientation, javafx.geometry.Pos.

Then we have created one class named TilePaneUI 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 TilePane with different tiles, a TilePane object is created which is then passed to the Scene class object.

TilePane is created with the help of its constructor. Then using ObservableList all the components are added to the list which is then set as Tiles.

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 invoked. In output Frame like container is displayed with the title, " JavaFX Layout – Tile Pane  Example”. Also, it displays TilePane with a new, open, save, cut, copy, paste, exit uniform-sized tiles placed in horizontal tile pane.

Layouts in JavaFX applications- TilePane

Layouts in JavaFX applications- Tile Pane with specified vgap and hgap

Example:

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;


public class TilePaneUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Button[] buttons = new Button[] { 
             new Button("New"), 
             new Button("Open"), 
             new Button("Save"), 
             new Button("Cut"), 
             new Button("Copy"), 
             new Button("Paste"), 
             new Button("Exit")  
          };   
          TilePane Pane = new TilePane();   
           
          Pane.setOrientation(Orientation.HORIZONTAL); 
           
          Pane.setTileAlignment(Pos.CENTER_LEFT); 
           
          Pane.setHgap(40);
          Pane.setVgap(20);
          
          ObservableList list = Pane.getChildren(); 
           
          list.addAll(buttons);
      
          Scene scene = new Scene(Pane);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle(" JavaFX Layout - Tile Pane Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the TilePane with defined spacing between tiles in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.control.Button,  javafx.scene.layout.TilePane, javafx.collections.ObservableList, javafx.geometry.Orientation, javafx.geometry.Pos.

Then we have created one class named TilePaneUI 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 TilePane with specified vgap and hgap between tiles, a TilePane object is created which is then passed to the Scene class object.

TilePane is created with the help of its constructor. Then using ObservableList all the components are added in the list which is then set as Tiles. The vgap and hgap is specified using setters.

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 invoked. In output Frame like container is displayed with the title, " JavaFX Layout – Tile Pane  Example”. Also, it displays TilePane with a new, open, save, cut, copy, paste, exit tiles with specified vgap and hgap.

Layouts in JavaFX applications- TilePane

Related Topics

JavaFX Transformation

In the JavaFX application, in order to apply various transformation effects, we use Transform class. It has the ability to create the transformation on the given object. This transformation changes...

3 minutes read.

JavaFX Motion Blur

In the JavaFX application, in order to apply various Motion blur effect, we use Motion Blur class. It has the ability to apply the Motion blur effect on the given...

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 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 Light Spot

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

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 Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

4 minutes read.

JavaFX Sequential Transition

In the JavaFX application, in order to generate the sequential transition, we have to apply sequential transition on any particular shape. It has the ability to execute multiple transactions sequentially...

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 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 Shear

In the JavaFX application, in order to apply various shear effect, we use this class. It has the ability to shear the given object along the x or y axis....

3 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

4 minutes read.

JavaFX Sphere

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

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 Label

The UI Control Label in a JavaFX is used to display the simple text. To use Label in JavaFX application javafx.scene.control.The label class is used. We can place Labels on...

3 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 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 Translate Transition

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

3 minutes read.