简体   繁体   English

如何在场景生成器中通过其fx:id查找元素

[英]How to find an element in Scene Builder by its fx:id

In Scene Builder I'm getting an warning every time I open a .fxml file. 在Scene Builder中,每次打开.fxml文件时都会收到警告。 The warning says: 警告说:

Duplicate usage of fx:id="x2" fx:id =“ x2”的重复使用

I don't remember to have set an fx:id of x2 to any element, but this is not really a problem. 我不记得已经为任何元素设置了x2fx:id ,但这并不是真正的问题。 The problem is that I have hundreds of elements in several different containers and it's very hard to find this two elements with this fx:id to fix this warning. 问题是我在几个不同的容器中有数百个元素,并且很难用此fx:id找到这两个元素来修复此警告。

Is there a way I can find an element in Scene Builder by searching it by its fx:id ? 有没有一种方法可以通过按其fx:id搜索在Scene Builder中找到元素?

EDIT 编辑

The element with duplicated id was an Insets , I'm not sure how it is created, but I'm sure that it's not visible neither in the Library area, nor in the Hierarchy area, nor in the main area of the Scene Builder. 具有重复ID的元素是Insets ,我不确定如何创建,但是我确定在Library区域,Hierarchy区域或Scene Builder的主区域中都不可见。 Their ids were duplicated somehow when I copied and pasted an HBox with an Label and a Button inside. 当我复制并粘贴带有标签和按钮的HBox时,它们的ID会以某种方式重复。 The ids of the HBox, Label and Button weren't duplicated, just the Insets' id was. HBox,Label和Button的ID没有重复,只是Insets的ID重复了。

The Insets looks like this in the source code: 源代码中的插图如下所示:

<HBox.margin>
    <Insets left="130.0" fx:id="x2" />
</HBox.margin>

I just removed their id and the problem was gone! 我只是删除了他们的ID,问题就消失了! Antoniossss' answer helped me. Antoniossss的回答对我有所帮助。

为什么不简单地使用文本编辑器编辑生成的fxml文件并在其中搜索x2

尝试下面的通过id获取元素

scene.lookup("#yourid");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM