1

有没有办法可以在边框窗格内找到月亮照片,使其位于中心而不是使用 javafx 的外部。下面是图片+代码。

(顺便说一句,我选择将月亮的图像放在标签内的原因是我可以在代码中的其他位置更新照片)

在此处输入图像描述

代码:

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);
4

1 回答 1

0

等等,最后,我按照下面的代码使用了 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;
    }
于 2013-09-11T11:17:52.117 回答