JavaFX 中的 fx:id 和 id: 有什么区别? [英] What's the difference between fx:id and id: in JavaFX?
问题描述
也许真的是新手的问题....
Maybe a really newbie's question....
通过阅读本教程,我开始使用 Scene Builder 在 FMXL 应用程序中学习 JavaFX:
I'm starting learning JavaFX in a FMXL Application using the Scene Builder, by reading this tutorials:
http://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm
因此,一旦我应用了一些更改,就会出现这 2 个 ID 的问题......我可能错过或混淆了它们......
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?
推荐答案
id
用于为组件设置 CSS ID,例如 #welcome-text { font-size: 16pt;}
所以这将应用于您的Text
.
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
如果你想在你的控制器类中使用你的组件,你可以使用 @FXML Text myWelcomeText
注释它们.
fx:id
you use if you want to work with your Components in your Controller class, where you annotate them with @FXML Text myWelcomeText
.
这篇关于JavaFX 中的 fx:id 和 id: 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!