package test; import java.util.ArrayList; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Control; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.image.ImageViewBuilder; import javafx.scene.layout.ColumnConstraintsBuilder; import javafx.scene.layout.GridPane; import javafx.scene.layout.RowConstraintsBuilder; import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPaneBuilder; import javafx.stage.Stage; public class Test extends Application { /** * @param args */ public static void main(String[] args) { launch(); } @Override public void start(Stage stage) throws Exception { StackPane sp = new StackPane(); Node n = getNode(); sp.getChildren().add(n); Scene scene = new Scene(sp, 500, 500); stage.setScene(scene); stage.show(); } private static double imageHeight = 11.2; private static double imageMarginHeight = 1.2; private static double imageWidth = 21.45; private static double zoneWidth = 3 * imageWidth + imageWidth / 2; private static double zoneHeight = 4 * imageMarginHeight + 2 * imageHeight; private static double rangeWidth = 3 * imageWidth; private static double rangeHeight = zoneHeight - imageHeight; public static Node getNode() { GridPane firstRange = new GridPane(); firstRange.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); firstRange.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); firstRange.setPrefSize(rangeWidth, rangeHeight); firstRange.getRowConstraints().addAll( RowConstraintsBuilder.create().percentHeight(100).build()); firstRange.getColumnConstraints().addAll( ColumnConstraintsBuilder.create() .percentWidth((double) 100 / (double) 3).build(), ColumnConstraintsBuilder.create() .percentWidth((double) 100 / (double) 3).build(), ColumnConstraintsBuilder.create() .percentWidth((double) 100 / (double) 3).build()); GridPane secondRange = new GridPane(); secondRange.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); secondRange.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); secondRange.setPrefSize(rangeWidth, rangeHeight); secondRange.getRowConstraints().addAll( RowConstraintsBuilder.create().percentHeight(100).build()); secondRange.getColumnConstraints().addAll( ColumnConstraintsBuilder.create().percentWidth(33).build(), ColumnConstraintsBuilder.create().percentWidth(33).build(), ColumnConstraintsBuilder.create().percentWidth(33).build()); StackPane[] sp = new StackPane[] { StackPaneBuilder.create().alignment(Pos.BOTTOM_CENTER).build(), StackPaneBuilder.create().alignment(Pos.BOTTOM_CENTER).build(), StackPaneBuilder.create().alignment(Pos.BOTTOM_CENTER).build(), StackPaneBuilder.create().alignment(Pos.BOTTOM_CENTER).build(), StackPaneBuilder.create().alignment(Pos.BOTTOM_CENTER).build(), StackPaneBuilder.create().alignment(Pos.BOTTOM_CENTER).build() }; for (int i = 0; i < 3; i++) { GridPane.setColumnIndex(sp[i], i); GridPane.setRowIndex(sp[i], 0); firstRange.getChildren().add(sp[i]); GridPane.setColumnIndex(sp[3 + i], i); GridPane.setRowIndex(sp[i], 0); secondRange.getChildren().add(sp[i + 3]); } StackPane res = new StackPane(); res.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); res.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); res.setPrefSize(zoneWidth, zoneHeight); StackPane.setAlignment(firstRange, Pos.TOP_CENTER); StackPane.setAlignment(secondRange, Pos.TOP_CENTER); StackPane.setMargin(secondRange, new Insets(imageHeight, 0, 0, imageWidth / 2)); res.getChildren().addAll(firstRange, secondRange); ArrayList chips = new ArrayList(); for (int count =0; count < 60; count++) { chips.add(ImageViewBuilder .create() .image(new Image(Test.class.getResourceAsStream("/test/test.png"))).fitWidth(imageWidth) .fitHeight(imageHeight).build()); } for (int index = 0; index < 60; index++) { int columnIndex = index / 10; sp[columnIndex].getChildren().add(chips.get(index)); StackPane.setMargin(chips.get(index), new Insets(0, 0, (index % 10) * imageMarginHeight, 0)); } return res; } }