官术网_书友最值得收藏!

TilePane and FlowPane

TilePane places nodes in the grid of the same-sized tiles. You can set preferable column and row counts, but TilePane will rearrange them as space allows. 

In the following example, you can see different rectangles being located in the same-sized tiles:

Refer to the following code:

// chapter1/layoutmanagers/TilePaneDemo.java
public class TilePaneDemo extends Application {

@Override
public void start(Stage primaryStage) {
TilePane root = new TilePane(5,5);
root.setPrefColumns(4);
root.setPrefRows(4);
// compare to
// FlowPane root = new FlowPane(5, 5);

for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
double size = 5 + 30 * Math.random();
Rectangle rect = new Rectangle(size, size,
(i+j)%2 == 0 ? Color.RED : Color.BLUE);
root.getChildren().add(rect);
}
}

Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle(root.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.show();
}
}

If you don't need tiles to have the same size, you can use FlowPane instead. It tries to squeeze as many elements in the line as their sizes allow. The corresponding FlowPaneDemo.java code sample differs from the last one only by the layout manager name, and produces the following layout:

主站蜘蛛池模板: 收藏| 中阳县| 云林县| 临沂市| 获嘉县| 苍梧县| 田阳县| 颍上县| 修文县| 开平市| 绍兴市| 鞍山市| 徐汇区| 教育| 剑河县| 海门市| 江达县| 宜丰县| 天津市| 泸溪县| 建始县| 凤山市| 凤山县| 大厂| 桂东县| 西贡区| 岗巴县| 永和县| 化州市| 新龙县| 西藏| 连城县| 渝中区| 南丰县| 沂水县| 唐河县| 乐至县| 日土县| 望都县| 滁州市| 岳西县|