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

后端 未结 4 871
广开言路
广开言路 2020-11-22 05:50

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

相关标签:
4条回答
  • 2020-11-22 06:01

    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.

    0 讨论(0)
  • 2020-11-22 06:02

    In JavaFX id is used to set a CSS ID to a component. And fx:id is used for accessing that component in code (i.e. in a controller class). fx:id works like a components name.

    0 讨论(0)
  • 2020-11-22 06:05

    I took a look at an FXML document generated using the JavaFX Scene Builder. You access controls from Java Controller with the fx:id. (edit) I stand corrected, the id does matter.

    You can apply css from the FXML document like this:

    <Slider id="css_id" fx:id="myslider" styleClass="style_name" .../>
    

    (Replace slider with any control)

    And Java controller interaction:

    @FXML
    Slider myslider;
    
    0 讨论(0)
  • 2020-11-22 06:24

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

    0 讨论(0)
提交回复
热议问题