JavaFX 8 Tutorial 55 - Centering Image Using StackPane
package tutorial.pkg55.centering.image; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Ellipse; import javafx.stage.Stage; /** * * @author Ram */ public class Tutorial55CenteringImage extends Application { @Override public void start(Stage primaryStage) { primaryStage.setTitle("JavaFX 8 Tutorial 55 - Centering Image Using StackPane"); StackPane root = new StackPane(); Scene scene = new Scene(root, 400, 200); Image img = new Image("file:Javafx.jpg", 100, 150, true, true); ImageView iv = new ImageView(img); Ellipse ellipse = new Ellipse(); ellipse.setFill(Color.MEDIUMSLATEBLUE); ellipse.radiusXProperty().bind(scene.widthProperty().divide(2));