【发布时间】:2016-07-08 16:32:16
【问题描述】:
我的菜单中有一个Imageview,它显示了所选地图的预览。
但是这些地图的大小可能会有所不同,在我的菜单中我有足够的水平空间,但在垂直方向上我有限制。所以,我想要的是缩放ImageView,使其高度变为 40 像素(我这里也有问题),并且宽度会相应地以不变形的方式发生变化。
如果有办法让高度自动适应它的线的高度,我会非常感激。(它的父级) 这是我的代码:
Label mapChooserLabel = new Label("This is the map you will play on, click to change");
try {
mapPreview = new ImageView(
new Image(getClass().getResource("/files/images/maps/" + chosenMapName + ".gif").toURI().toURL().toString())
);
mapPreview.setFitHeight(40);
mapPreview.setOnMouseClicked(event -> System.out.println("towerChooserPopup should open now!"));
} catch (MalformedURLException | URISyntaxException e) {
e.printStackTrace();
}
HBox mapChooserWrapper = new HBox(mapChooserLabel, mapPreview);
mapChooserWrapper.setId("lineWrapper");
这是我的 CSS:
#lineWrapper{
-fx-alignment: center;
-fx-spacing: 2px;
}
【问题讨论】:
标签: java javafx imageview scaling