JavaFX Tutorial - Java FlowPane .setPrefWrapLength (double value)








Syntax

FlowPane.setPrefWrapLength(double value) has the following syntax.

public final void setPrefWrapLength(double value)

Example

In the following code shows how to use FlowPane.setPrefWrapLength(double value) method.

/* w  w  w. ja va2s.com*/
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
 
public class Main extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("HTML");
        stage.setWidth(500);
        stage.setHeight(500);
        Scene scene = new Scene(new Group());
        
        FlowPane flow = new FlowPane(Orientation.VERTICAL);
        flow.setVgap(8);
        flow.setHgap(4);
        flow.setPrefWrapLength(300); // preferred width = 300
        for (int i = 0; i < 10; i++) {
            flow.getChildren().add(new Button("asdf"));
        }
        scene.setRoot(flow);
 
        stage.setScene(scene);
        stage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
}