Ale*_*lex 6 java javafx flowpane
我正在研究存储瓷砖网格的东西,并且我正在使用FlowPane,以便在调整窗口大小时瓷砖可以灵活地环绕.
我遇到的问题是屏幕右侧通常有很多空间,我想在两侧均匀分布.将对齐设置为中心类型的工作,但它将内容放在每一行的中心,我希望每一行在左侧开始刷新?
可视化我正在谈论的内容:
FlowPane对齐
知道我需要做什么吗?
您可以调整边框以获得更接近的输出。
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class JavaFXApplication95 extends Application
{
@Override
public void start(Stage primaryStage)
{
FlowPane flowPane = new FlowPane();
List<Circle> circleContainer = new ArrayList();
for(int i = 0; i < 5; i++)
{
Circle c1 = new Circle();
c1.setRadius(50);
c1.setFill(Color.BLUE);
circleContainer.add(c1);
}
flowPane.getChildren().addAll(circleContainer);
// flowPane.maxHeight(500);
// flowPane.setMaxWidth(300);
flowPane.setPadding(new Insets(30, 30, 30, 30));
StackPane root = new StackPane();
root.getChildren().add(flowPane);
Scene scene = new Scene(root, 600, 400);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)