[英]image location iside Borderpane in javafx
Is there a way I can locate the moon photo inside the Border Pane so that it is located in the center rather than outside using javafx. 有没有一种方法可以使用javafx在边界窗格中定位月球照片,使其位于中心而不是外部。 below is a picture + code.
下面是图片+代码。
(By the way, the reason I chose to put the image of the moon inside a label is so that I can update the photos else where in the code) (顺便说一句,我选择将月球图像放在标签内的原因是为了可以在代码中的其他位置更新照片)
Code: 码:
BorderPane Moonpane = new BorderPane();
Moonpane.setId("moonpane");
Moonpane.setPadding(new Insets(10, 0, 10, 10));
Moonpane.setPrefSize(290,70);
Moonpane.setMaxSize(290,70);
Moonpane.setMinSize(290,70);
ImageView Moon_img = new ImageView(new Image(getClass().getResourceAsStream("/Images/Moon/100%.png")));
Moon_img.setFitWidth(100);
Moon_img.setFitHeight(100);
Moon_img.setPreserveRatio(true);
Moon_img.setSmooth(true);
Moon_Image_Label.setGraphic(Moon_img);
Moonpane.setRight(Moon_Image_Label);
Moon_Date_Label.setId("moon-text-english");
Moonpane.setLeft(Moon_Date_Label);
Et voila and finally, I used Gridpane instead as per code below 等等,最后,我按照下面的代码使用了Gridpane
public GridPane moonpane() {
GridPane Moonpane = new GridPane();
Moonpane.setId("moonpane");
Moonpane.getColumnConstraints().setAll(
ColumnConstraintsBuilder.create().prefWidth(160).minWidth(160).build(),
ColumnConstraintsBuilder.create().prefWidth(100).minWidth(100).build()
);
Moonpane.setHgap(10);
Moonpane.setMaxHeight(50);
ImageView Moon_img = new ImageView(new Image(getClass().getResourceAsStream("/Images/Moon/100%.png")));
Moon_img.setFitWidth(100);
Moon_img.setFitHeight(100);
Moon_img.setPreserveRatio(true);
Moon_img.setSmooth(true);
Moon_Image_Label.setGraphic(Moon_img);
Moonpane.setConstraints(Moon_Image_Label, 1, 0);
Moonpane.getChildren().add(Moon_Image_Label);
Moon_Date_Label.setId("moon-text-english");
Moonpane.setConstraints(Moon_Date_Label, 0, 0);
Moonpane.getChildren().add(Moon_Date_Label);
Reflection r = new Reflection();
r.setFraction(0.15f);
Moonpane.setEffect(r);
Moonpane.setGridLinesVisible(true);
return Moonpane;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.