What's the difference between fx:id and id: in JavaFX?


Maybe a really newbie's question....

I'm starting learning JavaFX in a FMXL Application using the Scene Builder, by reading this tutorials:


So once i applied some changes, an issue with this 2 IDs came up... I might have missed or confused something about them...

Can anyone tell me in which cases they are used one or another?

6/4/2017 10:31:17 AM

Accepted Answer

id you use to set a CSS ID to your Component, for example <Text id="welcome-text" .../> and in your stylesheet you have something like #welcome-text { font-size: 16pt; } so this will be applied to your Text.

fx:id you use if you want to work with your Components in your Controller class, where you annotate them with @FXML Text myWelcomeText.

5/15/2014 9:26:28 PM

The fx:id is the identity associated to component in fxml to build a controller, and the id is used for css.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow