JavaFX TilePane Layout Tutorial with Examples

View more Tutorials:

Follow us on our fanpages to receive notifications every time there are new articles. Facebook Twitter

1- TilePane Layout

TilePane is a container which is so similar to FlowPane. It arranges the consecutive subcomponents on a row, and automatically pushes the subcomponents down to next line if the current line is filled up. However, it differs from FlowPane because the subcomponents lie on the same size cell.
The subcomponents lie on the same size grid cells

2- TilePane example


package org.o7planning.javafx.tilepane;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;

public class TilePaneDemo extends Application {

    public void start(Stage primaryStage) throws Exception {
        TilePane root = new TilePane();
        root.setPadding(new Insets(10,10,10,10));        
        Button button = new Button("Java");
        // Short Button
        Button button1 = new Button("C/C++");
        button1.setPrefSize(70, 50);
        // Short Button
        Button button2 = new Button("C#");
        // Button
        Button longButton3 = new Button("Objective C");
        // Button
        Button button4 = new Button("Swift");

        Scene scene = new Scene(root, 500, 300);
        primaryStage.setTitle("TilePanel Layout Demo (o7planning.org)");

    public static void main(String[] args) {

Running the example:

3- Design TitlePane on Scene Builder

It is easy for you to design the interface by using JavaFX Scane Builder. This below illustration shows the TilePane design with Scane Builder.
  • File/New/Other..
Open with Scene Builder:
Add Node to TilePane.
Setting Vgap, Hgap and padding.
Row Valignment & Column Halignment.

View more Tutorials:

Maybe you are interested

These are online courses outside the o7planning website that we introduced, which may include free or discounted courses.