怎么样更好的做网站千锋教育北京校区
JavaFX布局-SplitPane
- 常用属性
- orientation
- padding
- dividerPositions
- disable
- 实现方式
- Java实现
- fxml实现
- 一个拆分至少两个区域的容器
- 支持水平、垂直布局
- 可以拖动区域的大小
- 初始化大小通过比例设置[0,1]
常用属性
orientation
排列方式,Orientation.VERTICAL、Orientation.HORIZONTAL
splitPane.setOrientation(Orientation.HORIZONTAL);
padding
内边距,可以单独设置上、下、左、右的内边距
splitPane.setPadding(new Insets(10, 10, 10, 10));
dividerPositions
每个分割条的相对位置(介于0.0和1.0之间)
splitPane.setDividerPositions(0.33, 0.66);
disable
是是可以拖动改变区域大小
splitPane.setDisable(true);
实现方式
Java实现
public static SplitPane demo1() {SplitPane splitPane = new SplitPane();// 布局方向splitPane.setOrientation(Orientation.VERTICAL);// 内边距splitPane.setPadding(new Insets(10, 10, 10, 10));// 区域比例splitPane.setDividerPositions(0.33, 0.66);// 是否可拖动splitPane.setDisable(true);FlowPane flowPane1 = new FlowPane();flowPane1.setOrientation(Orientation.HORIZONTAL);flowPane1.setAlignment(Pos.CENTER);flowPane1.getChildren().add(new Circle(40, Color.RED));splitPane.getItems().add(flowPane1);FlowPane flowPane2 = new FlowPane();flowPane2.setOrientation(Orientation.HORIZONTAL);flowPane2.setAlignment(Pos.CENTER);flowPane2.getChildren().add(new Circle(50, Color.GREEN));splitPane.getItems().add(flowPane2);FlowPane flowPane3 = new FlowPane();flowPane3.setOrientation(Orientation.HORIZONTAL);flowPane3.setAlignment(Pos.CENTER);flowPane3.getChildren().add(new Circle(60, Color.BLUE));splitPane.getItems().add(flowPane3);return splitPane;}
fxml实现
<StackPane prefHeight="400" prefWidth="600" xmlns="http://javafx.com/javafx/17.0.2-ea"xmlns:fx="http://javafx.com/fxml/1"><children><SplitPane dividerPositions="0.33, 0.66" prefHeight="160.0" prefWidth="200.0" disable="true"><padding><Insets left="10" top="5" right="10" bottom="5"/></padding><items><FlowPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" orientation="VERTICAL"alignment="CENTER"><Circle radius="40" fill="red"/></FlowPane><FlowPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" orientation="VERTICAL"alignment="CENTER"><Circle radius="50" fill="green"/></FlowPane><FlowPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" orientation="VERTICAL"alignment="CENTER"><Circle radius="60" fill="blue"/></FlowPane></items></SplitPane></children>
</StackPane>