我对JavaFX很陌生并且我遇到了以下问题: 我有一个程序可以计算团队之间所有可能的匹配情况。这就是为什么总共有很多比赛的原因。我的问题出现了:我的ScrollPane包含一个包含VBox的AnchorPane(代码中的VBOX_matches)。该VBox包含基于所有可能匹配量的HBox。 我的想法是:因为它扩展了程序窗口的大小,所以必须看到其他匹配。让我们在论坛中添加一个滚动窗格。但是此滚动窗格始终保持在100%且不可滚动。我究竟做错了什么?这甚至可能吗?
https://ibb.co/c3WVEc //链接到屏幕截图。我不能以某种方式上传图片
this.matches = gameManagement.getMatches();
for (int i = 0; i < matches.size(); i++) {
String team1 = ((Team)((Pair)matches.get(i)).getKey()).getTeamname();
String team2 = ((Team)((Pair)matches.get(i)).getValue()).getTeamname();
HBox box = new HBox();
box.setSpacing(20);
Label first = new Label(team1);
first.setMinSize(LABEL_TEAM_WIDTH,LABEL_TEAM_HEIGHT);
first.setMaxSize(LABEL_TEAM_WIDTH,LABEL_TEAM_HEIGHT);
first.setPadding(new Insets(0,0,0,PADDING));
first.setTextAlignment(TextAlignment.CENTER);
first.setFont(Font.font("Bold",TEAM_FONT_SIZE));
box.getChildren().add(first);
VBOX_matches.getChildren().add(box);
FXML文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.media.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0"
prefWidth="1100.0" style="-fx-background-color: gray;" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.gui.GameController">
<children>
<SplitPane dividerPositions="0.6539162112932605" layoutX="377.0" layoutY="253.0" prefHeight="700.0"
prefWidth="1100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<ScrollPane fx:id="scroll" fitToHeight="true" fitToWidth="true" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" pannable="true"
prefHeight="698.0" prefWidth="682.0" vbarPolicy="ALWAYS"
SplitPane.resizableWithParent="false">
<content>
<AnchorPane fx:id="scroll_pane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="698.0" prefWidth="714.0">
<children>
<VBox fx:id="VBOX_matches" layoutX="-6.0" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="698.0" prefWidth="714.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/>
</children>
</AnchorPane>
</content>
</ScrollPane>