Thursday, May 24, 2012

Create TilePane using Java code

javafx.scene.layout.TilePane lays out its children in a grid of uniformly sized "tiles".

TilePane


package javafx_tilepane;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_TilePane extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("java-buddy.blogspot.com");
        
        TilePane horizontalTile = new TilePane();
        
        horizontalTile.setHgap(8);
        horizontalTile.setPrefColumns(4);
            for (int i = 0; i < 20; i++) {
                horizontalTile.getChildren().add(new ImageView("http://goo.gl/kYEQl"));
            }

        primaryStage.setScene(new Scene(horizontalTile, 450, 450));
        primaryStage.show();
    }
}


Related:
- TilePane in vertical
- Create TilePane using FXML


No comments:

Post a Comment