2 Replies Latest reply on May 2, 2013 4:54 PM by jsmith

    lookup() in ui tree from fxml and lookup from java built tree

    opfau
      Hi,

      when I try to find a control by its id I use the lookup()-Method. If I load the ui tree from fxml, I have to call something like root.lookup("#theControlId"). If I built the ui tree in java I can use look("theControlId"). Is this right? I am a little bit confused. Probably the id from fxml is used as id but is meant of the CSS id?
      What should I do If I have a mixed ui tree. Some parts from fxml, some parts java coded?


      Regards
      Oliver
        • 1. Re: lookup() in ui tree from fxml and lookup from java built tree
          opfau
          Search by id must be prefixed with #.
          • 2. Re: lookup() in ui tree from fxml and lookup from java built tree
            jsmith
            Probably the id from fxml is used as id but is meant of the CSS id?
            I think the rule is:

            1. If there is an fxml id and no css id explicitly set, then the fxml loader will set the css id of the element to the fxml id.
            2. If there are both an vxml id and a css id explicitly set, then the fxml loader will set the css id of the element to the explicit id.

            For instance:
            <Label text="Address Book" fx:id="book"/>
            ...
            @FXML Label book;
            After book is injected, it will have the the css id book assigned to it automatically and can be looked up up via:
            root.lookup("#book");
            <Label text="Address Book" fx:id="book" id="the-cat-in-the-hat"/>
            ...
            @FXML Label book;
            After book is injected, it will have the the css id the-cat-in-the-hat assigned to it automatically and can be looked up up via:
            root.lookup("#the-cat-in-the-hat");
            As opfl points out, in any case "Search by id must be prefixed with #"
            1 person found this helpful