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);
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短