×

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 Gradient Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the gradient colors in these shapes using the...

7 minutes read.

JavaFX Event Handling

JavaFX gives way to handle various events in web application, desktop applications and graphical applications. In the JavaFX application, in order to allow user to interact with application various events...

4 minutes read.

JavaFX Path Transition

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

3 minutes read.

JavaFX Selectors

In the JavaFX application, in order to apply various css effect, we use the various css classes available in the JavaFX. This is generally used to enhance the appearance property...

4 minutes read.

JavaFX Layouts

Layouts in the JavaFX application are treated as a container for different UI elements such as Button, Label, TextArea, etc. Layouts are used as parent container. The layout is used...

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 Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the colors in these shapes using the setFill()...

6 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX Stroke Transition

In the JavaFX application, in order to generate the stroke transition, we have to apply stroke transition on any particular shape. It has the ability to give different color strokes...

4 minutes read.

JavaFX Shadow

In the JavaFX application, in order to apply various Shadow effect from a single source, we use this class. It has the ability to create the shadow of the given...

3 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 minutes read.

JavaFX Color Input

In the JavaFX application, in order to apply various color input effect, we use the ColorInput class. It has the ability to fill the specified shape with a given color...

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

In the JavaFX application, in order to draw an Ellipse, the Ellipse class is used. The Ellipse allows us to join any points in the space to draw the unique...

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

In the JavaFX application, in order to apply various bloom effect, we use the Bloom class. It has the ability to bloom the colors of the shape. All methods needed...

4 minutes read.

JavaFX Fill Transition

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

4 minutes read.

JavaFX Drop Shadow

In the JavaFX application, in order to apply various Drop Shadow effect, we use this class. It has the ability to create the drop shadow of the given object. This...

4 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.