javaFX备忘录
博客专区 > fir01 的博客 > 博客详情
javaFX备忘录
fir01 发表于3年前
javaFX备忘录
  • 发表于 3年前
  • 阅读 226
  • 收藏 6
  • 点赞 0
  • 评论 0

华为云·免费上云实践>>>   

摘要: javaFX备忘录。一直用的是flex,目前flex转赠给apache好像支持力度不够,看下javaFX,企业组件也完善了,决定尝试一下

一直用的是flex,目前flex转apache好像支持力度不够,看下javaFX,企业组件也完善了,决定尝试一下。遇到一个问题,记录一下,备忘:

1、自适应布局几乎是标准布局。javaFX中有点奇特;

1)它没有width=100%,height=100%属性。

2)UI layout组件有些是默认自适应的,就是自动按父组件的高宽设置了100%的高和宽,有些又不是。

3)对于没有自动100%的组件,如VBox,HBox的子组件,如果你把TableView组件包在VBox下,发现它不会在纵轴方向自动100%宽度,而高度会自动100%。需要在组件设置类似属性:GridPane.hgrow="ALWAYS" VBox.vgrow="ALWAYS",很怪诞。而且这个属性是依赖父组件而存在的。如果父组件有GridPane,就设置GridPane.hgrow="ALWAYS",有VBox就设置VBox.vgrow="ALWAYS"。

贴个完整正确的自适应布局代码:

<?xml version="1.0" encoding="UTF-8"?>
<BorderPane prefHeight="404.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <top>
      <MenuBar BorderPane.alignment="CENTER">
        <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>
         <contextMenu>
            <ContextMenu>
              <items>
                <MenuItem mnemonicParsing="false" text="Unspecified Action" />
              </items>
            </ContextMenu>
         </contextMenu>
      </MenuBar>
   </top>
   <bottom>
      <HBox alignment="BOTTOM_LEFT" BorderPane.alignment="CENTER">
         <children>
            <Button mnemonicParsing="false" text="Button" />
            <Button mnemonicParsing="false" text="Button" />
         </children>
      </HBox>
   </bottom>
   <center>
      <SplitPane dividerPositions="0.5" orientation="VERTICAL">
         <items>
            <VBox GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
               <children>
                  <HBox maxHeight="-Infinity" prefWidth="598.0" GridPane.valignment="TOP" VBox.vgrow="ALWAYS">
                     <children>
                        <Label alignment="CENTER_RIGHT" layoutX="59.0" layoutY="4.0" prefHeight="25.0" prefWidth="99.0" text="Date" />
                        <TextField>
                           <HBox.margin>
                              <Insets left="10.0" />
                           </HBox.margin>
                        </TextField>
                        <Button alignment="BASELINE_LEFT" mnemonicParsing="false" text="search">
                           <HBox.margin>
                              <Insets left="10.0" />
                           </HBox.margin>
                        </Button>
                     </children>
                     <GridPane.margin>
                        <Insets top="10.0" />
                     </GridPane.margin>
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                     <padding>
                        <Insets bottom="5.0" top="5.0" />
                     </padding>
                  </HBox>
                  <TableView prefWidth="200.0" GridPane.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
                    <columns>
                      <TableColumn prefWidth="75.0" text="C1" />
                      <TableColumn prefWidth="75.0" text="C2" />
                    </columns>
                     <GridPane.margin>
                        <Insets top="40.0" />
                     </GridPane.margin>
                  </TableView>
               </children>
            </VBox>
            <TableView prefHeight="200.0" prefWidth="200.0">
              <columns>
                <TableColumn prefWidth="75.0" text="C1" />
                <TableColumn prefWidth="75.0" text="C2" />
              </columns>
            </TableView>
         </items>
      </SplitPane>
   </center>
</BorderPane>


共有 人打赏支持
粉丝 20
博文 99
码字总数 34117
×
fir01
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: