- JavaFX Tutorial
- JavaFX - Home
- JavaFX - Overview
- JavaFX Installation and Architecture
- JavaFX - Installation Using Netbeans
- JavaFX - Installation Using Eclipse
- JavaFX - Installation using Visual Studio Code
- JavaFX - Architecture
- JavaFX - Application
- JavaFX 2D Shapes
- JavaFX - 2D Shapes
- JavaFX - Drawing a Line
- JavaFX - Drawing a Rectangle
- JavaFX - Drawing a Rounded Rectangle
- JavaFX - Drawing a Circle
- JavaFX - Drawing an Ellipse
- JavaFX - Drawing a Polygon
- JavaFX - Drawing a Polyline
- JavaFX - Drawing a Cubic Curve
- JavaFX - Drawing a Quad Curve
- JavaFX - Drawing an Arc
- JavaFX - Drawing an SVGPath
- JavaFX Properties of 2D Objects
- JavaFX - Stroke Type Property
- JavaFX - Stroke Width Property
- JavaFX - Stroke Fill Property
- JavaFX - Stroke Property
- JavaFX - Stroke Line Join Property
- JavaFX - Stroke Miter Limit Property
- JavaFX - Stroke Line Cap Property
- JavaFX - Smooth Property
- Operations on 2D Objects
- JavaFX - 2D Shapes Operations
- JavaFX - Union Operation
- JavaFX - Intersection Operation
- JavaFX - Subtraction Operation
- JavaFX Color and Texture
- JavaFX - Colors
- JavaFX Text
- JavaFX - Text
- JavaFX Effects
- JavaFX - Effects
- JavaFX Transformations
- JavaFX - Transformations
- JavaFX Animations
- JavaFX - Animations
- JavaFX Images
- JavaFX - Images
- JavaFX 3D Shapes
- JavaFX - 3D Shapes
- JavaFX - Creating a Box
- JavaFX - Creating a Cylinder
- JavaFX - Creating a Sphere
- Properties of 3D Objects
- JavaFX - Cull Face Property
- JavaFX - Drawing Modes Property
- JavaFX - Material Property
- JavaFX Event Handling
- JavaFX - Event Handling
- JavaFX - Using Convenience Methods
- JavaFX - Event Filters
- JavaFX - Event Handlers
- JavaFX UI Controls
- JavaFX - UI Controls
- JavaFX - ListView
- JavaFX - Accordion
- JavaFX - ButtonBar
- JavaFX - ChoiceBox
- JavaFX - HTMLEditor
- JavaFX - MenuBar
- JavaFX - Pagination
- JavaFX - ProgressIndicator
- JavaFX - ScrollPane
- JavaFX - Separator
- JavaFX - Slider
- JavaFX - Spinner
- JavaFX - SplitPane
- JavaFX - TableView
- JavaFX - TabPane
- JavaFX - ToolBar
- JavaFX - TreeView
- JavaFX - Label
- JavaFX - CheckBox
- JavaFX - RadioButton
- JavaFX - TextField
- JavaFX - PasswordField
- JavaFX - FileChooser
- JavaFX - Hyperlink
- JavaFX - Tooltip
- JavaFX - Alert
- JavaFX - DatePicker
- JavaFX - TextArea
- JavaFX Charts
- JavaFX - Charts
- JavaFX - Creating Pie Chart
- JavaFX - Creating Line Chart
- JavaFX - Creating Area Chart
- JavaFX - Creating Bar Chart
- JavaFX - Creating Bubble Chart
- JavaFX - Creating Scatter Chart
- JavaFX - Creating Stacked Area Chart
- JavaFX - Creating Stacked Bar Chart
- JavaFX Layout Panes
- JavaFX - Layout Panes
- JavaFX - HBox Layout
- JavaFX - VBox Layout
- JavaFX - BorderPane Layout
- JavaFX - StackPane Layout
- JavaFX - TextFlow Layout
- JavaFX - AnchorPane Layout
- JavaFX - TilePane Layout
- JavaFX - GridPane Layout
- JavaFX - FlowPane Layout
- JavaFX CSS
- JavaFX - CSS
- Media with JavaFX
- JavaFX - Playing Video
- JavaFX Useful Resources
- JavaFX - Quick Guide
- JavaFX - Useful Resources
- JavaFX - Discussion
JavaFX - Layout TilePane
If we use this pane in our application, all the nodes added to it are arranged in the form of uniformly sized tiles. The class named tilePane of the package javafx.scene.layout represents the TilePane.
This class provides eleven properties, which are −
alignment − This property represents the alignment of the pane and you can set the value of this property using the setAlignment() method.
hgap − This property is of the type double and it represents the horizontal gap between each tile in a row.
vgap − This property is of the type double and it represents the vertical gap between each tile in a row.
orientation − This property represents the orientation of tiles in a row.
prefColumns − This property is of double type and it represents the preferred number of columns for a horizontal tile pane.
prefRows − This property is of double type and it represents the preferred number of rows for a vertical tile pane.
prefTileHeight − This property is of double type and it represents the preferred height of each tile.
prefTileWidth − This property is of double type and it represents the preferred width of each tile.
tileHeight − This property is of double type and it represents the actual height of each tile.
tileWidth − This property is of double type and it represents the actual width of each tile.
tileAlignment − This property is of double type and it represents the default alignment of each child within its tile.
Example
The following program is an example of the tile pane layout. In this, we are creating a tile pane which holds 7 buttons.
Save this code in a file with the name TilePaneExample.java.
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 TilePaneExample extends Application { @Override public void start(Stage stage) { //Creating an array of Buttons Button[] buttons = new Button[] { new Button("SunDay"), new Button("MonDay"), new Button("TuesDay"), new Button("WednesDay"), new Button("ThursDay"), new Button("FriDay"), new Button("SaturDay") }; //Creating a Tile Pane TilePane tilePane = new TilePane(); //Setting the orientation for the Tile Pane tilePane.setOrientation(Orientation.HORIZONTAL); //Setting the alignment for the Tile Pane tilePane.setTileAlignment(Pos.CENTER_LEFT); //Setting the preferred columns for the Tile Pane tilePane.setPrefRows(4); //Retrieving the observable list of the Tile Pane ObservableList list = tilePane.getChildren(); //Adding the array of buttons to the pane list.addAll(buttons); //Creating a scene object Scene scene = new Scene(tilePane); //Setting title to the Stage stage.setTitle("Tile Pane Example"); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } }
Compile and execute the saved java file from the command prompt using the following commands.
javac TilePaneExample.java java TilePaneExample
On executing, the above program generates a JavaFX window as shown below.