JavaFX场景生成器 - 设置可调整大小的Rectangle

时间:2014-10-29 09:02:43

标签: java javafx scenebuilder

我使用Scene Builder和JavaFX。我尝试使用不同的背景颜色在我的应用程序中创建侧边栏。

我的AnchorPane中有一个矩形,我希望矩形始终与窗口高度相匹配。因此,当我调整窗口大小时,矩形高度应该会改变。出于某种原因,矩形属性中禁用了resizable复选框。

如果使用Scene Builder不容易实现,除了矩形之外,还有其他可用于此目的的组件吗?

1 个答案:

答案 0 :(得分:2)

你可以像这样使用它。我希望你的问题能够得到解决。

enter image description here

在这里,您可以看到包含边框窗格的锚定窗格。在Top-Section中我添加一个MenuBar,在左侧部分我添加一个VBOX,中心包含一个BarChart。页脚只是一个内部带有标签的HBox。

这是获得您想要的最简单方法!

这是以下代码:

    <?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="410.0" prefWidth="599.9998779296875" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
  <children>
    <AnchorPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <children>
        <BorderPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
          <bottom>
            <HBox alignment="CENTER" prefHeight="24.0" prefWidth="600.0" style="-fx-background-color:lightgrey;">
              <children>
                <Label text="This is a Footer Section" />
              </children>
            </HBox>
          </bottom>
          <center>
            <VBox prefHeight="200.0" prefWidth="100.0" style="-fx-background-color:grey;">
              <children>
                <BarChart>
                  <xAxis>
                    <CategoryAxis side="BOTTOM" />
                  </xAxis>
                  <yAxis>
                    <NumberAxis side="LEFT" />
                  </yAxis>
                </BarChart>
              </children>
            </VBox>
          </center>
          <left>
            <VBox alignment="TOP_CENTER" prefHeight="352.0" prefWidth="90.0" style="-fx-background-color:darkgrey;">
              <children>
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
                <Button mnemonicParsing="false" text="SidebarItem" />
              </children>
            </VBox>
          </left>
          <right>
            <VBox prefHeight="352.0" prefWidth="56.0" style="-fx-background-color:darkgrey;" />
          </right>
          <top>
            <MenuBar>
              <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>
          </top>
        </BorderPane>
      </children>
    </AnchorPane>
  </children>
</AnchorPane>

Lukas Adler