【发布时间】:2021-02-28 08:42:26
【问题描述】:
这是我的 FXML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox prefHeight="Infinity" prefWidth="936.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Add Files…" />
<MenuItem mnemonicParsing="false" text="Save As…" />
<MenuItem mnemonicParsing="false" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About This App" />
</items>
</Menu>
</menus>
</MenuBar>
<HBox maxHeight="Infinity" maxWidth="Infinity" prefHeight="429.0" prefWidth="1048.0">
<children>
<StackPane prefHeight="Infinity" prefWidth="681.0">
<children>
<ListView maxHeight="Infinity" maxWidth="Infinity" prefHeight="Infinity" prefWidth="690.0" />
<Button mnemonicParsing="false" text="Add Files...">
<font>
<Font size="15.0" />
</font>
</Button>
</children>
</StackPane>
<VBox prefHeight="300.0" prefWidth="130.0">
<children>
<ImageView accessibleRoleDescription="Preview" accessibleText="Preview" fitHeight="172.0" fitWidth="364.0" pickOnBounds="true" preserveRatio="true" />
<VBox prefHeight="78.0" prefWidth="48.0">
<children>
<Button mnemonicParsing="false" prefHeight="30.0" prefWidth="120.0" text="Move Down" />
<Button mnemonicParsing="false" prefHeight="30.0" prefWidth="120.0" text="Move Up" />
<Button mnemonicParsing="false" prefHeight="30.0" prefWidth="120.0" text="Remove" />
</children>
</VBox>
</children>
</VBox>
</children>
</HBox>
</children>
</VBox>
当我调整窗口大小时,ListView 不会覆盖整个屏幕:
我希望它在调整大小时粘在屏幕底部。有什么属性可以为我做到这一点吗?我应该在哪个元素上应用它?如果我的 FXML 太长,用一个简单的解释一下怎么做。
【问题讨论】:
-
layout.prefHeightProperty().bind(stage.heightProperty())呢? -
将您的
VBox包裹在AnchorPane中,并将您的VBox锚定到它。 -
将
VBox.vgrow="ALWAYS"属性添加到包含ListView的HBox元素。如果您还希望ListView水平增长,请将HBox.hgrow="ALWAYS"属性添加到ListView元素。 -
你正在硬编码包含
ListView的HBox的高度,所以当你增加窗口的高度时它当然不会增长。