Как изменить размер ImageView при изменении размера окна в графическом интерфейсе javafx

<?php

class Dude {
    const TEST = 'howdy';
}

function symbol_to_value($symbol, $class){
    $refl = new ReflectionClass($class);
    $enum = $refl->getConstants();
    return isset($enum[$symbol])?$enum[$symbol]:false;
}

// print 'howdy'
echo symbol_to_value('TEST', 'Dude');
0
задан AutoStudent 18 March 2019 в 15:27
поделиться

1 ответ

Вы можете использовать привязку для простоты, здесь полный пример кода

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage){
        GridPane gridPane = new GridPane();
        AnchorPane anchorPane = new AnchorPane();

        // Set image with url
        Image image = new Image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR-524e2cCaY9TUn8vglN3nqqOlT0jIJIIty-Z81S49q9Np6Yws");
        ImageView imageView = new ImageView(image);

        // Bind the imageView width property to gridPane width property
        // So, if width of gridPane change, the width of imageView automatically will be change
        imageView.fitWidthProperty().bind(gridPane.widthProperty());

        // Make the ratio same with original image
        imageView.setPreserveRatio(true);

        anchorPane.getChildren().add(imageView);
        gridPane.getChildren().add(anchorPane);
        Scene scene = new Scene(gridPane, 600, 400);
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Fullscreen

Not fullscreen [114 ]

0
ответ дан NM Naufaldo 18 March 2019 в 15:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: