无法使用滚动窗格滚动充满标签的 VBox



基本上是列出一个加起来的标签列表。当它们到达底部时,它们超出了它们的界限(也必须在 TextField 后面(,并且无法滚动它。 如何让他们表现正常? 标签被添加到滚动窗格内的 VBox 中

有问题的图片: 这里

场景生成器截图: 这里

FXML文件:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.canvas.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="root" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.view.GameUIController">
<children>
<SplitPane dividerPositions="0.6889632107023411" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<SplitPane dividerPositions="0.8737373737373737" orientation="VERTICAL" prefHeight="398.0" prefWidth="407.0">
<items>
<AnchorPane minWidth="0.0" prefWidth="160.0">
<children>
<ScrollPane fx:id="scrollPane" fitToHeight="true" fitToWidth="true" pannable="true" prefWidth="407.0" vvalue="1.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<VBox fx:id="box" minWidth="0.0" />
</content>
</ScrollPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<TextField fx:id="textField" onAction="#enterPressed" prefHeight="20.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="-5.0" AnchorPane.rightAnchor="5.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<SplitPane dividerPositions="0.5" layoutY="44.0" orientation="VERTICAL" prefHeight="398.0" prefWidth="181.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane fx:id="inventoryPane" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<Label layoutX="48.0" layoutY="30.0" text="Inventory" textAlignment="CENTER" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<font>
<Font size="22.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane fx:id="playerPane" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<Label text="Player" textAlignment="CENTER">
<font>
<Font size="22.0" />
</font>
</Label>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

标签添加方法在另一个线程中(由于游戏机制原因(

@FXML
public void text(String text1) {
Platform.runLater(new Runnable() {
@Override
public void run() {
Label label = new Label(text1);
box.getChildren().add(label);
}
});
listener = false;
// scroll to bottom
}

从 fxmlfitToHeight="true"中删除它,它工作好运,伙计。

显然我的游戏引擎类看不到正确的节点,所以我将它们从控制器传递到引擎方法中。现在像魅力一样工作

相关内容

  • 没有找到相关文章

最新更新