javafx 瓷砖
示例
平铺窗格的布局类似于FlowPane布局。TilePane将所有节点放在一个网格中,每个单元或图块的大小均相同。它将节点水平或垂直排列在整齐的行和列中。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("TilePane Demo");
double width = 400;
double height = 300;
TilePane root = new TilePane();
root.setStyle("-fx-background-color:blue");
//设置水平和垂直间隙
root.setHgap(20);
root.setVgap(50);
Button bl = new Button("Buttons");
root.getChildren().add(bl);
Button btn = new Button("Button");
root.getChildren().add(btn);
Button btn1 = new Button("Button 1");
root.getChildren().add(btn1);
Button btn2 = new Button("Button 2");
root.getChildren().add(btn2);
Button btn3 = new Button("Button 3");
root.getChildren().add(btn3);
Button btn4 = new Button("Button 4");
root.getChildren().add(btn4);
Scene scene = new Scene(root, width, height);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}输出
创建图块
TilePane root = new TilePane();
setHgap()并且使用setVgap()方法来使列与列之间形成间隙。我们还可以通过使用以下方式设置布局的列
int columnCount = 2; root.setPrefColumns(columnCount);
热门推荐
2 红丝绒戚风蛋糕
3 夹心小甜点
4 南瓜甜点
6 粘米粉蒸蛋糕
7 酸奶华夫饼
9 红柚鸡蛋糕
10 葡萄干蛋糕
11 紫薯蛋糕卷
13 纸杯裱花小蛋糕
14 果酱奶酪蛋糕
15 日式樱花蔓越莓大福
16 草莓蛋糕卷
17 卡仕达长崎杯子蛋糕