瓦片、瓷砖的意思,整齐排列,无缝衔接,就像你家的地板。类似于flow,区别见下
先来两张效果图::
老规矩点赞评论拿代码不然代码必爆红(划掉,太恶毒)。
package sample;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Button b1 = new Button("b1");
Button b2 = new Button("b2");
Button b3 = new Button("b3");
Button b4 = new Button("b4");
Button b5 = new Button("b5");
Button b6 = new Button("b6");
Button b7 = new Button("b7");
Button b8 = new Button("b8");
TilePane tlp = new TilePane();//瓦片、瓷砖的意思,整齐排列,无缝衔接,就像你家的地板。类似于flow,区别见下
tlp.setStyle("-fx-background-color: #07f379");
tlp.getChildren().addAll(b1, b2, b3, b4, b5, b6, b7, b8);
tlp.setHgap(10);//设置水平间距
tlp.setVgap(10);//设置垂直间距
//三个重要方法::内边距、外边距、对齐方式
tlp.setPadding(new Insets(10));
tlp.setMargin(b1, new Insets(15));//设置b1的外边距,会使得当前行的所有控件按照b1效果动态变化,这是于Flow的最大区别之一,
b1.setPrefHeight(200);//设置b1的高度后会使得同一行的按钮居中对齐b1,老师原话一家人一定要整整齐齐!!
b1.setPrefWidth(200);垂直也会整整齐齐的对齐,铺地板的老板们学一学!不行就抹水泥
tlp.setAlignment(Pos.BOTTOM_CENTER);//向下居中
Scene scene = new Scene(tlp);
primaryStage.setScene(scene);
primaryStage.setTitle("Java FX Lesson21.TilePane ");
primaryStage.setWidth(800);
primaryStage.setHeight(800);
primaryStage.show();
}
}