Element does not define a default property


Question

I'm working with JavaFX and trying to use FXML, however I've never had any sort of formal training in it, so I'm kind of stumbling about.

I keep running into this here error: Caused by: javafx.fxml.LoadException: Element does not define a default property.

My aim is to try to initialize a Custom Controller class that runs its own FXML file. The code example given by Oracle therefore looks like this:

<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml"> 
  <TextField fx:id="textField"/>
  <Button text="Click Me" onAction="#doSomething"/>
</fx:root>

where the controller and root is set in the Controller method.

I'm trying to adapt this code to my own needs, and I was wondering if someone could explain to me why this error comes up if the fx:root type="javafx.scene.layout.VBox" is ever changed to something like fx:root type="javafx.scene.Parent" if you want me to, I can post some actual code samples.

1
2
4/21/2014 8:14:52 AM

The concept of default-property is introduced to short circuit your FXML in reality you'd have to write:

<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml"> 
  <children>
    <TextField fx:id="textField"/>
    <Button text="Click Me" onAction="#doSomething"/>
  </children>
</fx:root>

if you now change the container type to Parent and you browse the parent class you'll notice that it does not define a children-property which you implicitly assume - children is introduced by Pane.

You should probably read http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html

3
4/21/2014 9:49:39 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon