JavaFx-TilePane

Program

dsds

 

Program Source

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundSize;

public class JavaFXApplication extends Application {
    
    public static void main(String[] args) {
        
        Application.launch(args);
    }
    
    public void start(Stage primaryStage) {
        
        primaryStage.setTitle("TilePane");
        
        Group root = new Group();
        Scene scene = new Scene(root, 700, 250, Color.GREY);
        
        TilePane tile = new TilePane();
        tile.setLayoutX(140);
        tile.setLayoutY(50);
        tile.setHgap(20);
        tile.setVgap(20);
        tile.setPrefColumns(5);
        Image image = new Image ("http://hajsoftutorial.com/im/background.png");
        tile.setBackground(new Background(new BackgroundImage(image,BackgroundRepeat.REPEAT,
                                                                  BackgroundRepeat.REPEAT,
                                                                  BackgroundPosition.DEFAULT,
                                                                  BackgroundSize.DEFAULT)));
        Button[] btn = new Button[20];
        for(int i=0; i<20; i++) 
        {
            btn[i] = new Button("Button "+i);
            tile.getChildren().add(btn[i]);
        }
        
        root.getChildren().add(tile);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Leave a Comment