Question

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. 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)

enter image description here

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);
Was it helpful?

Solution

Et voila and finally, I used Gridpane instead as per code below

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;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top