JavaFX Tutorial - Java TilePane .setPrefTileWidth (double value)








Syntax

TilePane.setPrefTileWidth(double value) has the following syntax.

public final void setPrefTileWidth(double value)

Example

In the following code shows how to use TilePane.setPrefTileWidth(double value) method.

/*from w w  w .  j  a  v  a  2s.c o m*/
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 450, 250);

    TilePane tile = new TilePane();
  
    tile.setHgap(8);
    tile.setPrefColumns(4);
    for (int i = 0; i < 20; i++) {
      tile.getChildren().add(new CheckBox("CheckBox"));
    }
    tile.setPrefTileWidth(0.8);
    
    HBox hbox = new HBox(10);
    hbox.setPadding(new Insets(20, 0, 0, 20));
    hbox.getChildren().setAll(tile);
    
    
    Group root = (Group) scene.getRoot();
    root.getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
  }
}