Class TilePane

java.lang.Object
All Implemented Interfaces:
Styleable, EventTarget

public class TilePane extends Pane
TilePane lays out its children in a grid of uniformly sized "tiles".

A horizontal tilepane (the default) will tile nodes in rows, wrapping at the tilepane's width. A vertical tilepane will tile nodes in columns, wrapping at the tilepane's height.

The size of each "tile" defaults to the size needed to encompass the largest preferred width and height of the tilepane's children and the tilepane will recompute the size of the tiles as needed to accommodate the largest preferred size of its children as it changes. The application may also control the size of the tiles directly by setting prefTileWidth/prefTileHeight properties to a value other than USE_COMPUTED_SIZE (the default).

Applications should initialize either prefColumns (for horizontal) or prefRows (for vertical) to establish the tilepane's preferred size (the arbitrary default is 5). Note that prefColumns/prefRows is used only for calculating the preferred size and may not reflect the actual number of rows or columns, which may change as the tilepane is resized and the tiles are wrapped at its actual boundaries.

The alignment property controls how the rows and columns are aligned within the bounds of the tilepane and defaults to Pos.TOP_LEFT. It is also possible to control the alignment of nodes within the individual tiles by setting tileAlignment, which defaults to Pos.CENTER.

A horizontal tilepane example:


    TilePane tile = new TilePane();
    tile.setHgap(8);
    tile.setPrefColumns(4);
    for (int i = 0; i < 20; i++) {
        tile.getChildren().add(new ImageView(...));
    }
 

A vertical TilePane example:


    TilePane tile = new TilePane(Orientation.VERTICAL);
    tile.setTileAlignment(Pos.CENTER_LEFT);
    tile.setPrefRows(10);
    for (int i = 0; i < 50; i++) {
        tile.getChildren().add(new ImageView(...));
    }
 
The TilePane will attempt to resize each child to fill its tile. If the child could not be sized to fill the tile (either because it was not resizable or its size limits prevented it) then it will be aligned within the tile using tileAlignment.

Resizable Range

A tilepane's parent will resize the tilepane within the tilepane's resizable range during layout. By default the tilepane computes this range based on its content as outlined in the tables below.

Horizontal
widthheight
minimum left/right insets plus the tile width. top/bottom insets plus height required to display all tiles when wrapped at a specified width with a vgap between each row.
preferred left/right insets plus prefColumns multiplied by the tile width. top/bottom insets plus height required to display all tiles when wrapped at a specified width with a vgap between each row.
maximum Double.MAX_VALUEDouble.MAX_VALUE

Vertical
widthheight
minimum left/right insets plus width required to display all tiles when wrapped at a specified height with an hgap between each column. top/bottom insets plus the tile height.
preferred left/right insets plus width required to display all tiles when wrapped at the specified height with an hgap between each column. top/bottom insets plus prefRows multiplied by the tile height.
maximum Double.MAX_VALUEDouble.MAX_VALUE

A tilepane's unbounded maximum width and height are an indication to the parent that it may be resized beyond its preferred size to fill whatever space is assigned to it.

TilePane provides properties for setting the size range directly. These properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the application may set them to other values as needed:


     tilePane.setMaxWidth(500);
 
Applications may restore the computed values by setting these properties back to Region.USE_COMPUTED_SIZE.

TilePane does not clip its content by default, so it is possible that children's' bounds may extend outside the tiles (and possibly the tilepane bounds) if a child's pref size prevents it from being fit within its tile. Also, if the tilepane is resized smaller than its preferred size, it may not be able to fit all the tiles within its bounds and the content will extend outside.

Optional Layout Constraints

An application may set constraints on individual children to customize TilePane's layout. For each constraint, TilePane provides a static method for setting it on the child.

TilePane Constraint Table
ConstraintTypeDescription
alignmentjavafx.geometry.PosThe alignment of the child within its tile.
marginjavafx.geometry.InsetsMargin space around the outside of the child.

Example:


     TilePane tilepane = new TilePane();
     for (int i = 0; i < 20; i++) {
        Label title = new Label(imageTitle[i]):
        Imageview imageview = new ImageView(new Image(imageName[i]));
        TilePane.setAlignment(label, Pos.BOTTOM_RIGHT);
        tilepane.getChildren().addAll(title, imageview);
     }
 
Since:
JavaFX 2.0