6 Replies Latest reply: Apr 29, 2013 3:21 AM by 982084 RSS

    Scene Builder: cannot edit when I embed a custom control!

    982084
      Hi guys, I'm having an issue with Scene Builder and embedded custom controls...

      I have a LoginPanel .fxml/.java module, which contains two re-usable custom controls I've built:
      * StatusZone .fxml/.java
      * LanguageSelector .fxml/.java

      The application runs.

      However, I can't open LoginPanel.fxml to edit it with SceneBuilder v1.1 (developer preview).

      To be specific, in LoginPanel.fxml, I have this data:
      <StatusZone fx:id="statusZone" />
      <LanguageSelector fx:id="languageSelector" />

      -----

      SCENARIO 1
      -- LoginPanel.fxml --
      <?import kalungcasev2.view.StatusZone?>
      <?import kalungcasev2.view.LanguageSelector?>

      I get:
      Warning: File 'LoginPanel.fxml' contains references to types that could not be loaded.
      Missing types are [kalungcasev2.view.StatusZone]

      I can click 'Set up classpath', but no matter which folder I choose, it doesn't seem to fix the problem.

      -----

      SCENARIO 2:
      -- LoginPanel.fxml --
      <?import kalungcasev2.view.*?>

      I get:
      Warning: File 'LoginPanel.fxml' contains references to types that could not be loaded.
      Missing types are: [StatusZone, LanguageSelector]

      I can click 'Set up classpath', but no matter which folder I choose, it doesn't seem to fix the problem.

      -----

      How do I fix this?
        • 1. Re: Scene Builder: cannot edit when I embed a custom control!
          daniel
          Hi,

          Did you compile your custom types first? Did you click on 'Apply'?

          regards,

          -- daniel
          • 2. Re: Scene Builder: cannot edit when I embed a custom control!
            982084
            Hi Daniel,

            I press the 'Build Project' button (and let the operation complete) before opening the FXML file. Is this what you meant?

            Also, when I do choose the path to my 'view' package, I click Apply, yet nothing happens besides a status message telling me that the FXML file has been refreshed. Pressing 'Close' afterwards shows me the scene but without my embedded custom controls.
            • 3. Re: Scene Builder: cannot edit when I embed a custom control!
              daniel
              Hi,
              when I do choose the path to my 'view' package [...]
              Just to make things clear:

              I assume you have something like that on disk:

              build/
              build/classes/
              build/classes/kalungcasev2/
              build/classes/kalungcasev2/view/
              build/classes/kalungcasev2/view/LanguageSelector.class
              build/classes/kalungcasev2/view/StatusZone.class

              If so the folder you must select is 'build/classes' - not 'build/classes/kalungcasev2/view'

              Also do StatusZone.fxml and LanguageSelector.fxml also ocntain custom types?
              If they do - then you might need to properly configure the ClassLoader in the FXMLLoader that loads them.
              public StatusZone() {
                   ...
                   FXMLLoader loader = new FXMLLoader();
                   loader.setLocation(....)
                   loader.setClassLoader(this.getClass().getClassLoader());    <<<<<  
                
                   Node n = loader.load();
                   ...
              }
              Hope this helps,

              -- daniel
              • 4. Re: Scene Builder: cannot edit when I embed a custom control!
                982084
                Hi Daniel,

                Your help is VERY appreciated. Indeed, selecting 'build/classes' instead of the .java files' location did resolve the issue for me!

                However, while it is true that my custom components do not embed other custom components themselves... if they did, what would be the guideline when it comes to configure the class loader?

                loader.setClassLoader(this.getClass().getClassLoader());

                What would I need to change in the above line?
                • 5. Re: Scene Builder: cannot edit when I embed a custom control!
                  daniel
                  Hi,

                  If no ClassLoader is configured in the FXMLLoader, then the FXMLLoader will try to load the
                  classes using the System/Context class loader.

                  This works well in the context of an application where everything is in the system class loader.
                  In SceneBuilder however - your classes will not be in the System class loader, but in a special
                  URL class loader that SceneBuilder created for your FXML file.

                  SceneBuilder sets this ClassLoader on the FXMLLoader that loads your top FXML file,
                  but it can't do anything for the instances of FXMLLoader that your own code creates.

                  Therefore - it's best to configure your FXMLLoader with the appropriate class loader,
                  which is usually the class loader that loaded your custom type.

                  See https://javafx-jira.kenai.com/browse/DTL-5177 for more details.

                  -- daniel

                  Edited by: daniel on Apr 25, 2013 7:33 AM

                  Sorry - to be more precise:
                  loader.setClassLoader(this.getClass().getClassLoader());
                  is the correct line.
                  • 6. Re: Scene Builder: cannot edit when I embed a custom control!
                    982084
                    Hi Daniel,

                    Thank you for all your assistance. It's truly appreciated. Question is now answered.