简体   繁体   中英

JavaFX Scene Builder - set Rectangle resizable

I'm using Scene Builder with JavaFX. I'm trying to create a sidebar in my application with a difference background color.

I have a rectangle in my AnchorPane and I want the rectangle to always match the window height. So when I resize the window, the rectangle height should change. For some reason the resizable checkbox is disabled in the rectangle properties.

If this is not easily possible using Scene Builder, is there another component I can use for this purpose, other than rectangle?

you can use it like this. I hope your Problem will be solved.

在此处输入图片说明

Here you can see a Anchor Pane which includes the Border Pane. In the Top-Section i add a MenuBar, in the Left Section i add a VBOX and the Center includes a BarChart. The Footer is only a HBox with a Label inside.

This is the easiest way to get what you want i think!

This is the following code:

    <?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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM