在JavaFX中,fx:id和id:有什么区别? [英] What's the difference between fx:id and id: in JavaFX?

查看:201
本文介绍了在JavaFX中,fx:id和id:有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许是一个非常新手的问题....



我正在使用Scene Builder开始在FMXL应用程序中学习JavaFX,阅读本教程:



http ://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm



所以,一旦我应用了一些更改,这2个ID的问题出现了...我可能已经错过或混淆了一些关于他们的事情......



任何人都可以告诉我他们在哪些情况下使用过它们或者另一个?

解决方案

id 您用来设置 CSS ID 到你的组件,例如< Text id =welcome-text... /> 并在你的样式表中你有类似<$ c $的东西c>#welcome-text {font-size:16pt; } 所以这将应用于你的文本



fx:id 如果你想在Controller类中使用你的组件,你可以使用它们,你可以用 @FXML Text myWelcomeText 注释它们。 / p>

Maybe a really newbie's question....

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

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 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.

这篇关于在JavaFX中,fx:id和id:有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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