为什么myLabel内容未显示在我的网格窗格中,这很奇怪,其他所有内容都显示了。
我已经尽力了。任何帮助,请
这是我的代码片段和结果的图片
@Override public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 1180, 650);
stage.setScene(scene);
stage.setTitle("Prayer Time Display");
scene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm());
GridPane Mainpane = new GridPane();
scene.setRoot(Mainpane);
Mainpane.setGridLinesVisible(true);
Mainpane.setId("Mainpane");
GridPane prayertime_pane = new GridPane();
prayertime_pane.setId("prayertime_pane");
prayertime_pane.setPadding(new Insets(20, 20, 20, 20));
prayertime_pane.setAlignment(Pos.BASELINE_CENTER);
prayertime_pane.setVgap(7);
prayertime_pane.setHgap(35);
GridPane moon_pane = new GridPane();
moon_pane.setGridLinesVisible(true);
moon_pane.setPadding(new Insets(10, 10, 10, 10));
moon_pane.setAlignment(Pos.BASELINE_CENTER);
moon_pane.setVgap(10);
moon_pane.setHgap(10);
myLabel.setText("hello");
moon_pane.setConstraints(myLabel, 0, 0);
moon_pane.getChildren().add(myLabel);
ImageView Moon_img = new ImageView(new Image(getClass().getResourceAsStream("/Images/Full_Moon.png")));
Moon_img.setFitWidth(100);
Moon_img.setFitHeight(100);
moon_pane.add(Moon_img, 1, 0);
Text next_moon_text = new Text("13/02");
next_moon_text.setId("prayer-text-english");
moon_pane.setHalignment(next_moon_text,HPos.LEFT);
moon_pane.setValignment(next_moon_text,VPos.CENTER);
moon_pane.setConstraints(next_moon_text, 2, 0);
moon_pane.getChildren().add(next_moon_text);
Mainpane.add(moon_pane, 8, 1,3,2);
您的标签确实出现在场景中,但已缩小到仅呈现文本溢出字符的程度-“ ...”
为确保始终以适合所有文本的固定宽度呈现标签,您可以强制将最小和最大宽度与首选宽度相同:
myLabel.setMinWidth(Region.USE_PREF_SIZE);
myLabel.setMaxWidth(Region.USE_PREF_SIZE);
如果要保留动态大小,则可以始终使用Scenic View(http://fxexperience.com/scenic-view/)分析场景图,并确定哪些节点或容器占用了所有空间或具有大小限制
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句