如何解决标签未在 ScrollPane 中正确换行
将 FlowPane 添加到 ScrollPane 中的另一个窗格时遇到问题。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ScrollProblem extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
ScrollPane sc = new ScrollPane();
VBox vBox = new VBox();
sc.setContent(vBox);
sc.setFitToWidth(true);
sc.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
vBox.getChildren().addAll(
new Lbl("Some text"),new Lbl("Some longer text that surpasses the width of the window"),// When I remove this FlowPane from the code,then everything works. When I add it
// to the code,then the Labels do not wrap correctly.
new FlowPane(
new Lbl("A flowpane containing some other text")
)
);
Scene scene = new Scene(sc);
primaryStage.setScene(scene);
primaryStage.setWidth(200);
primaryStage.setHeight(400);
primaryStage.show();
}
private class Lbl extends Label {
public Lbl(String text) {
super(text);
this.setWrapText(true);
}
}
}
这是没有流窗格的样子(以及它应该是什么样子):
当我调整这个窗口的大小时,文本仍然正确换行。
这是带有流窗格的样子:
如您所见,流窗格内的标签没有换行。 此外,当我调整窗口大小时,其他标签不再换行:
先谢谢你!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。