码迷,mamicode.com
首页 > 编程语言 > 详细

javaFX备忘录

时间:2015-04-15 15:10:44      阅读:666      评论:0      收藏:0      [点我收藏+]

标签:

一直用的是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>


javaFX备忘录

标签:

原文地址:http://my.oschina.net/fir01/blog/401772

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!