问题描述
将 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 (将#修改为@)