1

在应用程序中,一个 FXML 被加载到另一个 FXML 的 AnchorPane 中。问题是 ListView 的 AnchorPane 约束(正好是底部)不想在调整大小期间工作。

加载的文件代码:

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

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

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="-1.0" prefWidth="-1.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
  <children>
    <HBox cache="true" cacheHint="SPEED" fillHeight="true" minHeight="-1.0" prefHeight="-1.0" prefWidth="1280.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <children>
        <TabPane id="navPane" cache="true" cacheHint="SPEED" maxWidth="-1.0" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="420.0" rotateGraphic="false" side="LEFT" tabClosingPolicy="UNAVAILABLE" tabMaxHeight="1.7976931348623157E308" tabMinHeight="30.0" HBox.hgrow="NEVER">
          <tabs>
            <Tab closable="true" text="Untitled Tab 1">
              <content>
                <AnchorPane id="AnchorPane" fx:id="homePane" cache="true" cacheHint="SPEED" maxHeight="-1.0" maxWidth="-1.0" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" style="-fx-background-color: red;">
                  <children>
                    <StackPane id="navPaneHeaderPane" cache="true" cacheHint="SPEED" prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                      <children>
                        <AnchorPane id="navPaneHeaderPane" cache="true" cacheHint="SPEED" prefHeight="200.0" prefWidth="200.0" style="" />
                        <Label id="navPaneHeaderString" cache="true" cacheHint="SPEED" text="Label" StackPane.alignment="CENTER" />
                      </children>
                    </StackPane>
                    <TextField cache="true" cacheHint="SPEED" prefHeight="30.0" prefWidth="294.0" AnchorPane.leftAnchor="28.0" AnchorPane.rightAnchor="28.0" AnchorPane.topAnchor="55.0" />
                    <Separator cache="true" cacheHint="SPEED" prefWidth="200.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="100.0" />
                    <ListView fx:id="listView" cache="true" cacheHint="SPEED" minHeight="-1.0" minWidth="-1.0" pickOnBounds="true" prefHeight="-1.0" prefWidth="-1.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="120.0" />
                  </children>
                </AnchorPane>
              </content>
            </Tab>
            <Tab text="Untitled Tab 2">
              <content>
                <AnchorPane id="Content" cache="true" cacheHint="SPEED" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
              </content>
            </Tab>
          </tabs>
        </TabPane>
        <AnchorPane cache="true" cacheHint="SPEED" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
          <children>
            <TableView cache="true" cacheHint="SPEED" prefHeight="700.0" prefWidth="860.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="0.0">
              <columns>
                <TableColumn prefWidth="75.0" text="Column X" />
                <TableColumn prefWidth="75.0" text="Column X" />
              </columns>
            </TableView>
          </children>
        </AnchorPane>
      </children>
      <stylesheets>
        <URL value="@../../../../skins/default.css" />
      </stylesheets>
    </HBox>
  </children>
</AnchorPane>

加载上述 FXML 的文件的代码:

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

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?scenebuilder-preview-i18n-resource ../lang/ru_RU.properties?>

<AnchorPane id="AnchorPane" fx:id="mainStage" cache="true" cacheHint="SPEED" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="UI.PrimaryStageController">
  <children>
    <StackPane fx:id="toolbarStack" alignment="CENTER_LEFT" cache="true" cacheHint="SPEED" prefHeight="100.0" prefWidth="1280.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="100.0" AnchorPane.topAnchor="0.0">
      <children>
        <FlowPane fx:id="toolbarPane" cache="true" cacheHint="SPEED" maxHeight="-Infinity" minHeight="-Infinity" prefHeight="100.0" prefWidth="1280.0" style="">
          <children>
            <Button id="fileButton" fx:id="selectorButton" cache="true" cacheHint="SPEED" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#openSelector" prefHeight="100.0" prefWidth="100.0" text="%selectorButton" />
            <Button fx:id="fileButton" cache="true" cacheHint="SPEED" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#openFileMenu" prefHeight="100.0" prefWidth="100.0" text="%fileButton">
              <stylesheets>
                <URL value="@../../skins/default.css" />
              </stylesheets>
            </Button>
            <Button fx:id="toolsButton" cache="true" cacheHint="SPEED" mnemonicParsing="false" onAction="#openToolsMenu" prefHeight="100.0" prefWidth="100.0" text="Button" />
            <Button fx:id="helpButton" cache="true" cacheHint="SPEED" mnemonicParsing="false" onAction="#openHelpMenu" prefHeight="100.0" prefWidth="100.0" text="Button" />
          </children>
        </FlowPane>
      </children>
    </StackPane>
    <AnchorPane fx:id="contentPane" prefHeight="-1.0" prefWidth="-1.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="100.0" />
    <Button cache="true" cacheHint="SPEED" mnemonicParsing="false" onAction="#closeApp" prefHeight="100.0" prefWidth="100.0" text="%exitButton" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
  </children>
  <stylesheets>
    <URL value="@../../skins/default.css" />
  </stylesheets>
</AnchorPane>

第一个 FXML 使用fx:id = "contentPane". 由于我不知道 ListViewfx:id = "listView"在窗口调整大小期间不会调整大小的原因。有任何想法吗?PS我使用JavaFX 8

4

0 回答 0