javafx内部控件自动拉伸设置

北战南征 提交于 2020-07-28 22:09:48

1、使用HBOX和VBox包含控件,这样内部控件就有VGrow和HGrow属性,就可以进行自动拉伸的设置。

2、AnchorPane控件包含的内部控件可以使用AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"让内部控件拉伸到外部控件。

<AnchorPane fx:id="anchorpane" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="641.0"  xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.joe.readwritemacs.controller.WriteReadMacViewController">
   <children>
      <VBox fx:id="vbox" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="52.0" prefWidth="698.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="0.0">
         <children>
            <MenuBar fx:id="menuBar" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
              <menus>
                <Menu mnemonicParsing="false" text="File">
                  <items>
                    <MenuItem mnemonicParsing="false" text="Close" />
                  </items>
                </Menu>
                <Menu mnemonicParsing="false" text="Edit">
                  <items>
                    <MenuItem mnemonicParsing="false" text="Delete" />
                  </items>
                </Menu>
                <Menu mnemonicParsing="false" text="Help">
                  <items>
                    <MenuItem mnemonicParsing="false" text="About" />
                  </items>
                </Menu>
              </menus>
            </MenuBar>
            <Button fx:id="btn" mnemonicParsing="false" text="Button" />
         </children></VBox>
   </children>
</AnchorPane>

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!