如何将图像视图置于锚窗格中心? [英] How do I center an Image view in an anchor pane?

查看:312
本文介绍了如何将图像视图置于锚窗格中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用场景构建器来创建我的GUI,并且当用户选择列表中的项目时,我正在显示图像图像具有不同的大小,当图像小于它所在的窗格时,图像是显示在窗格的左上角。如何获取 ImageView 和/或图像显示在<$ c $的中心c> Pane ?

I am using scene builder to create my GUI and I am displaying Images as users select items in a list. The Images are of different sizes and when an Image that is smaller than the pane it is in, the image is displayed in the top left of the pane. How do I go about getting the ImageView and/or Image to be displayed in the center of the Pane?

我看过整个javafx imageview和图像API,但我没有找到很多关于<$ c的中心$ c> ImageView 在窗格中。我也没有在场景构建器中看到任何东西。通常在场景构建器中,如果有一种方法可以使节点居中,则会有一个居中选项。

I've looked throughout the javafx imageview and image APIs but I haven't found much on centering the ImageViewin a Pane. I haven't seen anything in scene builder, either. Usually in scene builder, if there is a way to center a node, there will be an option for centering.

推荐答案

现在可以在特定位置设置图像对齐的窗格...为此你可以使用try HBox

In any kind of pane its now possible to set image alignment in specific postion.. for this you can use try HBox

当您将图像插入 HBox 时,最初显示如下所示。

when you insert an Image into the HBox, initially its shown like below.

现已设定 HBox的对齐属性

现在将对齐更改为居中并查看输出

now change the alignment to centre and see the output

我希望它为你工作

也可以通过获取图像在 Pane 中以编程方式执行此操作

Its also possible to do so programmatically in a Pane via get image

试试这个

AnchorPane anchorPane = new AnchorPane();
Image img = new Image(getClass().getResourceAsStream("Edit-Male-User-icon.png"));
ImageView imageView = new ImageView(img);
anch.getChildren().add(imageView );
ImageView app = (ImageView) (Node) anchorPane.getChildren().get(0);
app.setX(100);
app.setY(100);

这篇关于如何将图像视图置于锚窗格中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆