简体   繁体   中英

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. The warning says:

Duplicate usage of 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. 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.

Is there a way I can find an element in Scene Builder by searching it by its fx:id ?

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. Their ids were duplicated somehow when I copied and pasted an HBox with an Label and a Button inside. The ids of the HBox, Label and Button weren't duplicated, just the Insets' id was.

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! Antoniossss' answer helped me.

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

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

scene.lookup("#yourid");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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