FlowPane preferred width allows for two columns : FlowPane « JavaFX « Java






FlowPane preferred width allows for two columns

  
 
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage primaryStage) {
    primaryStage.setTitle("FlowPane example");

    FlowPane flowPane = new FlowPane();
    flowPane.setPadding(new Insets(10, 10, 10, 10));
    flowPane.setVgap(4);
    flowPane.setHgap(4);
    flowPane.setPrefWrapLength(210);

    Button btn = new Button();

    for (int i = 0; i < 8; i++) {

      btn = new Button("Button");
      btn.setPrefSize(100, 50);
      flowPane.getChildren().add(btn);

    }

    Scene scene = new Scene(flowPane);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
}

   
    
  








Related examples in the same category

1.Adding Buttons to flow pane
2.Example of a horizontal flowpane
3.Adding controls to FlowPane
4.Set vertical and horizontal gap for FlowPane