JavaFX:避免指定绝对宽度

时间:2014-07-17 07:48:09

标签: javafx splitpane

SplitPane中有一个SplitPane - 两个都是横向的。我想避免指定绝对宽度/高度。如果我没有指定宽度/高度,则不会显示第二个SplitPane

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

<?import javafx.scene.control.*?>
<?import javafx.scene.Group?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="500.0" style="-fx-background-color: cornsilk;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <left>
        <ToolBar orientation="VERTICAL">
            <items>
                <Group>
                    <children>
                        <Button rotate="-90.0" text="Project" />
                    </children>
                </Group>
                <Group>
                    <children>
                        <Button rotate="-90.0" text="Structure" />
                    </children>
                </Group>
            </items>
        </ToolBar>
    </left>
    <center>
      <SplitPane dividerPositions="0.25" style="-fx-background-color:red;">
        <items>
          <AnchorPane  style="-fx-background-color:darkblue;"/>
          <AnchorPane  style="-fx-background-color:gold;">
              <children>
                  <SplitPane dividerPositions="0.25">
                      <items>
                          <AnchorPane style="-fx-background-color:khaki;"/>
                          <AnchorPane style="-fx-background-color:lime;"/>
                      </items>
                  </SplitPane>
              </children>
          </AnchorPane>
        </items>
      </SplitPane>
    </center>
</BorderPane>

1 个答案:

答案 0 :(得分:0)

使用SplitPane定义<SplitPane dividerPositions="0.25" AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">修复了问题,这是MWE:

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

<?import javafx.scene.control.*?>
<?import javafx.scene.Group?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="700.0" style="-fx-background-color: cornsilk;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <left>
        <ToolBar orientation="VERTICAL">
            <items>
                <Group>
                    <children>
                        <Button rotate="-90.0" text="Project" />
                    </children>
                </Group>
                <Group>
                    <children>
                        <Button rotate="-90.0" text="Structure" />
                    </children>
                </Group>
            </items>
        </ToolBar>
    </left>
    <center>
      <SplitPane dividerPositions="0.25" style="-fx-background-color:red;">
        <items>
          <AnchorPane  style="-fx-background-color:green;"/>
          <AnchorPane  style="-fx-background-color:blue;">
              <children>
                  <SplitPane dividerPositions="0.25" AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                      <items>
                          <AnchorPane style="-fx-background-color:black;"/>
                          <AnchorPane style="-fx-background-color:aqua;"/>
                      </items>
                  </SplitPane>
              </children>
          </AnchorPane>
        </items>
      </SplitPane>
    </center>
</BorderPane>