BorderPane在上,左,右,底部和中间位置摆放孩子
demo1方位布局类 BorderPane 如果其中的某个方位没有组件,会被其他组件挤占空间
中间优先挤占四周,顶部和底部会优先挤占左右;
AnchorPane ap1 = new AnchorPane();
ap1.setPrefWidth(100);
ap1.setPrefHeight(100);
ap1.setStyle("-fx-background-color: #7FFFD4");
AnchorPane ap2 = new AnchorPane();
ap2.setPrefWidth(100);
ap2.setPrefHeight(100);
ap2.setStyle("-fx-background-color: #C1FFC1");
AnchorPane ap3 = new AnchorPane();
ap3.setPrefWidth(100);
ap3.setPrefHeight(100);
ap3.setStyle("-fx-background-color: #458B00");
AnchorPane ap4 = new AnchorPane();
ap4.setPrefWidth(100);
ap4.setPrefHeight(100);
ap4.setStyle("-fx-background-color:#EE82EE");
AnchorPane ap5 = new AnchorPane();
ap5.setPrefWidth(100);
ap5.setPrefHeight(100);
ap5.setStyle("-fx-background-color: #FFDAB9");
BorderPane bor = new BorderPane();
bor.setTop(ap1);//设置顶部
bor.setBottom(ap2);//设置底部
bor.setLeft(ap3);//设置左边
bor.setRight(ap4);//设置右边
bor.setCenter(ap5);//设置中间
Scene scene = new Scene(bor);
primaryStage.setScene(scene);
primaryStage.setTitle("lesson16");
primaryStage.setWidth(800);
primaryStage.setHeight(800);
primaryStage.show();
demo2
网友评论