我认为这两个属性的定义是相同的。在“correct.fxml”网格中,如果我添加 1 行或 1 列,则会出现相应的 ScrollPane 滚动条。在“wrong.fxml”网格中不会发生这种情况,我不明白为什么。也许我没有看到它们之间的区别。感谢您的帮助。
正确.fxml
错误.fxml
正确.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="429.0"
prefWidth="761.0" stylesheets="@stylesheet.css" xmlns="http://javafx.com/javafx/22"
xmlns:fx="http://javafx.com/fxml/1">
<center>
<ScrollPane BorderPane.alignment="CENTER">
<content>
<StackPane>
<children>
<Pane StackPane.alignment="CENTER">
<children>
<GridPane alignment="CENTER" hgap="1.0" vgap="1.0">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
</rowConstraints>
</GridPane>
</children>
</Pane>
</children>
</StackPane>
</content>
</ScrollPane>
</center>
</BorderPane>
错误.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<BorderPane prefHeight="277.0" prefWidth="495.0" xmlns="http://javafx.com/javafx/22"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="br.com.ablogic.crossword.MainViewController">
<center>
<ScrollPane fx:id="scpGrid" fitToHeight="true" fitToWidth="true"
focusTraversable="false" BorderPane.alignment="CENTER">
<content>
<StackPane fx:id="stkPane">
<children>
<Pane fx:id="pane" StackPane.alignment="CENTER">
<children>
<GridPane alignment="CENTER" hgap="1.0" vgap="1.0">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
<ColumnConstraints halignment="CENTER" hgrow="NEVER"
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="40.0" minHeight="40.0"
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
</rowConstraints>
</GridPane>
</children>
</Pane>
</children>
</StackPane>
</content>
</ScrollPane>
</center>
</BorderPane>