如果我将自动换行设置为标签并将其放入任何布局 - 自动换行工作正常,除非我将标签放入 ScrollPane。这是一个例子:
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Test");
BorderPane borderPane = new BorderPane();
VBox myView = new VBox();
Label label = new Label("Lorem ipsum dolor sit amet, consectetur adipisicing elit," +
" sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim" +
" ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip" +
" ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" +
" velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat" +
" cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum");
label.setWrapText(true);
myView.getChildren().addAll(label);
ScrollPane scroll = new ScrollPane();
scroll.setContent(myView);
scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
borderPane.setCenter(scroll);
Scene scene = new Scene(borderPane, 300, 400);
primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
有什么方法可以在滚动窗格内进行自动换行吗?