如何在tilepane,JavaFX中获取imageview的价值? [英] How to get the value of imageview in tilepane, JavaFX?

查看:207
本文介绍了如何在tilepane,JavaFX中获取imageview的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaFX中制作了一个tilepane。我在tilepane上放了一些imageview。

I made a tilepane in JavaFX. And I put some imageview on tilepane.

我想得到的tilepane(第一行,第一列)中imageview中的图像值。

I want to get the value of image in imageview in tilepane(first row, first column).

此值



| 0,0 | 0,1 | 0,2 | 0,3 | 0,4 |



| 1,0 | 1,1 | 1,2 | 1,3 | 1,4 |



我试图

| 0,0 | 0,1 | 0,2 | 0,3 | 0,4 |

| 1,0 | 1,1 | 1,2 | 1,3 | 1,4 |

I tried to

System.out.println(tilepane.getChildren().get(0))

=> result:Pane @ 2fc42278

=> result : Pane@2fc42278

我可以访问tilepane(第一行,第一列)。
但我无法获得内在价值。我的最终目标是获取图像的名称。
如何获得图片的价值?

I can access to tilepane(first row, first column). But I can't get the inner value. My final goal is getting the image's name. How can I get the value of image?

提前致谢!

推荐答案

Node有一个方法 setUserData ,您可以将任何对象放入其中。您可以通过setUserData方法为ImageView对象指定名称。

A Node has a method setUserData into which you can put any object. You could assign the ImageView object a name via the setUserData method.

通过TitledPane迭代将是这样的:

Iterating through the TitledPane would be like this:

    TitledPane pane = ...
    for( Node child: pane.getChildrenUnmodifiable()) {
        if( child instanceof ImageView) {
            ImageView imageView = (ImageView) child;
            System.out.println( imageView.getUserData());
        }
    }

这样你检查ImageView。但是当然你也可以在不检查ImageView的情况下检查所有节点的userData。

That way you check for ImageView. But of course you could as well check the userData of all nodes without checking for ImageView.

这篇关于如何在tilepane,JavaFX中获取imageview的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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