Javafx 2 ScrollPane内HBox中包装的JavaFX标签不起作用

Javafx 2 ScrollPane内HBox中包装的JavaFX标签不起作用,javafx-2,Javafx 2,我尝试使用ScrollPane进行滚动,并使用VBox进行查看(scroll.setContent(VBox);)。每条消息在其中创建新的HBox和标签。 标签包含文本并声明text.setWrapText(true) 当有足够的空间而不滚动其工作时: 但是,当消息高度大于VHox高度(查看滚动窗格)时,包装不起作用: 编辑:相关代码: import javafx.application.Application; import javafx.scene.Scene; import javaf

我尝试使用
ScrollPane
进行滚动,并使用
VBox
进行查看(
scroll.setContent(VBox);
)。每条消息在其中创建新的
HBox
标签。
标签包含文本并声明
text.setWrapText(true)

当有足够的空间而不滚动其工作时:

但是,当消息高度大于
VHox
高度(查看
滚动窗格
)时,包装不起作用:

编辑:相关代码:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ChatExample extends Application
{
    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception
    {
        ScrollPane scroll = new ScrollPane();
        scroll.setFitToHeight(true);
        scroll.setPrefSize(300, 300);
        VBox chat = new VBox();
        chat.setSpacing(10);
        scroll.setContent(chat);

        chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message"));
        chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message"));
        chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message"));
        chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message"));

        final Scene scene = new Scene(scroll, 300, 300);

        stage.setScene(scene);
        stage.show();
    }

    public HBox addMessage(String message)
    {
        HBox hbox = new HBox();
        Label label = new Label(message);
        label.setWrapText(true);
        label.setMaxWidth(50);

        hbox.getChildren().add(label);
        return hbox;
    }
}

多亏@sillyfly编写了一个小例子,我才知道这种情况是什么情况


scroll.setFitToHeight(真)
制造了这个问题,所以我删除了它

请发布一个(又名MCVE)。据我所知,fitToHeight用于使消息从下到上显示。请您展示一下这个小例子,以了解这个问题的原因是什么,以及是否有任何解决办法,因为我需要这个fitToHeight功能。