簡體   English   中英

javafx中的圖像位置iside Borderpane

[英]image location iside Borderpane in javafx

有沒有一種方法可以使用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);

等等,最后,我按照下面的代碼使用了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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM