2017-09-18 1 views
0

나는 사각형과 이미지가 위에있는 그룹을 가지고 있습니다. 직사각형 크기를 다시 지정하고 이미지가 사각형 크기보다 작은 경우를 제외하고 이미지 크기가 고정되어 있어야합니다. 그런 다음 이미지는 사각형과 함께 축소되어야합니다.JavaFX 축소 이미지 뷰

이미지는 항상 중앙에 위치해야하며 약간의 패딩이 있어야합니다.

이미지의 축소 부분을 제외하고는 대부분 이러한 부분을 수행했습니다. 왜 그런지는 모르겠지만 이미지의 크기가 전혀 줄어들지는 않습니다. 이것이 내가 가진 것입니다.

Group group = new Group() 
    GeometryNode<Rectangle> rectangle = new GeometryNode<>(); 
    rectangle.setGeometry(new Rectangle(0, 0, 60, 60)); 

    ImageView imageView = new ImageView(image); 
    imageView.setPreserveRatio(true); 

    ImageViewPane imagePane = new ImageViewPane(imageView); 
    imagePane.setMinSize(0, 0); 
    imagePane.setMaxSize(50, 50); 

    StackPane stackPane = new StackPane(); 

    stackPane.getChildren().add(rectangle); 
    stackPane.getChildren().add(imagePane); 
    group.getChildren().add(stackPane); 

답변

1

당신은 ImageViewfitWidthfitHeight 속성은 StackPane 변화의 치수 경우 변경하고 싶습니다. 할 수 있으니

double padding = ... ; 

imageView.setPreserveRatio(true); 
imageView.fitWidthProperty().bind(
    Bindings.min(stackPane.widthProperty().subtract(padding), image.widthProperty())); 
imageView.fitHeightProperty().bind(
    Bindings.min(stackPane.heightProperty().subtract(padding), image.heightProperty()));