FlowPane流式布局

  • 创建流式布局

    // 创建8个按钮  
    Button[] buttons = new Button[8];  
    for (int i = 0; i < buttons.length; i++) {  
        buttons[i] = new Button("Button " + i);  
    }  
    // 创建流式布局  
    FlowPane flowPane = new FlowPane();  
    flowPane.setStyle("-fx-background-color: #336699;");  
    flowPane.getChildren().addAll(buttons);
    
  • 设置垂直流式布局(默认为水平流式布局)flowPane.setOrientation(Orientation.VERTICAL);

  • 设置对齐方式:水平居中、垂直居中flowPane.setAlignment(Pos.CENTER);

  • 设置组件间水平间距flowPane.setHgap(10);

  • 设置组件间垂直间距flowPane.setVgap(10);

  • 设置边距flowPane.setPadding(new Insets(10));

  • 设置第一个按钮的外边距此时其他按钮距离顶部的距离也会随着改变FlowPane.setMargin(buttons[0], new Insets(10));