N
N
Neonoviiwolf2018-02-04 16:48:01
JavaFX
Neonoviiwolf, 2018-02-04 16:48:01

How to center View in ViewImage?

Kind
The problem is probably simple, but even I don’t know how to ask a question to Google.
I have an imageView, I add a picture to it. it is aligned to the top left, i need it to be centered
like this in fxml

<ImageView fx:id="imageView" fitHeight="200" fitWidth="200"
               pickOnBounds="true"
               preserveRatio="true"/>

the code
public class ImageDownloadLayoutController implements Initializable {
    @FXML
    ImageView imageView;
    @FXML
    Button addImage, downloadImage;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        File file = new File("src/test/1.jpg");
        Image image = new Image(file.toURI().toString());
        imageView.setImage(image);
    }
}

looks like this
5a770eff59aa2425838601.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question