- Mastering JavaFX 10
- Sergey Grinev
- 188字
- 2021-06-25 21:21:53
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:

推薦閱讀
- 黑客攻防實戰(zhàn)技術完全手冊:掃描、嗅探、入侵與防御
- 通信網(wǎng)絡基礎與設備
- 物聯(lián)網(wǎng)概論(第2版)
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- SD-WAN架構與技術(第2版)
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- 中國互聯(lián)網(wǎng)發(fā)展報告2018
- 基于性能的保障理論與方法
- 夢工廠之材質(zhì)N次方:Maya材質(zhì)手冊
- 物聯(lián)網(wǎng)與智能家居
- Hands-On Microservices with Node.js
- Practical Web Penetration Testing
- 數(shù)據(jù)血緣分析原理與實踐
- 沖擊:5G如何改變世界
- 全聯(lián)網(wǎng)標識服務