Scene Builder and<fx:root>

Daniel Fuchs daniel.fuchs at
Fri Jul 13 01:02:47 PDT 2012

On 7/12/12 7:22 PM, openjfx-dev-request at wrote:
> Date: Thu, 12 Jul 2012 19:08:37 +0200
> From: Werner Lehmann<lehmann at>
> Subject: Re: Scene Builder and<fx:root>
> To:openjfx-dev at
> Message-ID:<4FFF0495.3010202 at>
> Content-Type: text/plain; charset="windows-1252"; format=flowed

Hi Werner,

(sorry if this is a duplicate - I replied yesterday but forgot to
  fix the subject line - left (Re: openjfx-dev Digest, Vol 8, Issue 25)
  so I think my reply was lost)

> Daniel,
> On 12.07.2012 18:28, Daniel Fuchs wrote:
>> >  As Greg says - you will need to provide a value for the
>> >  fx:type attribute in fx:root - and you should be able
>> >  to load that in SceneBuilder.
>> >
>> >  SceneBuilder does not allow you to set fx:root from within
>> >  SceneBuilder itself (I mean, if you create an FXML from
>> >  within SceneBuilder it will not have the fx:root element) - but
>> >  if you load an FXML whose root element is fx:root then
>> >  SceneBuilder should be able to load it, and will preserve it.
> that works indeed. I just had to use "BorderPane" as fx:root type
> attribute value instead of my derived class which SB cannot know about.
> What about my other question as to how custom controls can be used in
> Scene Builder? Can I add them to the library, and would it pick up any
> new properties on the right hand side of the SB window? Or, is it
> possible to just manually edit that part of the FXML but still use SB
> for the rest of it?

I see several questions here:

1. No you cannot add your own controls to the Library with
    SceneBuilder 1.0.

2. However if your FXML already contains your own controls,
    SceneBuilder should be able to load it, unless they require
    specific  builders/builder factory.

     At first load SceneBuilder will recognize that your FXML
     contains types that it does not know about - and will pop up
     dialog allowing you to enter a classpath.

     In some cases, SceneBuilder might be able to load the file even
     if you choose to not provide a classpath - but in that case -
     the unknown types will not be displayed - neither on the content
     view - nor in the hierarchy panel.
     Their FXML elements will be preserved however.

     If you choose to provide a classpath however, SceneBuilder
     should be able to render your custom controls, and you will be
     able to manipulate them.
     The properties that are specific to your controls will appear in
     a 'Miscellaneous' category in the inspector on the right hand

     Since SceneBuilder doesn't know about your custom types - it
     might not be able to display their subnodes in the Hierarchy
     Panel. For instance - if your control extends Pane,
     then SceneBuilder will assume that the children are to be found
     in the Pane.getChildren() property. However - if it extends
     Region directly - then the children will not be displayed in
     the hierarchy.
     In other words SceneBuilder sees the scenegraph through the
     lens of the javafx classes it knows about.

3. If you have provided a classpath - then copy/paste should work
    also for your custom types. So if you have an instance of
    "FooControl" you should be able to use copy/paste to create
    another one.

4. Be also aware that if your custom control behave badly -
    then anything could happen - for instance if one of your
    custom controls enters in an infinite loop during layout it
    can block the UI.

In practice - if you wish to add your own controls and work with
them in SceneBuilder you could:

a. create a skeleton FXML using SceneBuilder
b. at the place where you would like to insert your own control,
    insert instead a place holder instance of its closest JavaFX
    super class.
c. save and close the file.
d. In NetBeans or Eclipse (or emacs ;-)) change the name of the
    place holder element, replace the name of the javafx class with
    your own custom class.
    Don't forget to add the appropriate <?import ?> clause at
    the beginning of the FXML file.
e. From File > Open Recent > - open your file again. You will get
    the popup asking for a classpath. Provide the classpath and
    you should be able to load the file.

hope this helps,

-- daniel

> Werner

More information about the openjfx-dev mailing list