Java Reference
In-Depth Information
Using FXDNode to load objects
You can use the FXNode class directly to load the top-most group encapsulated in the FXD
file. This approach works well when you are interested in loading all objects in the scene graph
as a group quickly, and place them on the scene or in another container node.
var artwork = FXDNode {
url: "{__DIR__}SymbolsPS.fxz"
}
Variable artwork will be an instance of an orphaned Node . Therefore, you can nest artwork
in a container node, such as Scene or another group as follows:
Scene{content: artwork }
Accessing Group nodes directly
If your artwork has several nested groups, as do vector graphics exported from SVG or
Illustrator, you can use FXDNode to load them directly as shown below:
var artwork = FXDNode {
url: "{__DIR__}SymbolsPS.fxz"
}
def flare = artwork.getGroup("flare");
This method returns a Group instance of the selected object.
Accessing objects directly
You can also use the FXDNode instance to access individual graphics objects nested
inside the FXD file's scene graph by their IDs.
var artwork = FXDNode {
url: "{__DIR__}SymbolsPS.fxz"
}
def triangle = artwork.getNode("triangle") as ImageView;
def target = artwork.getNode("target") as ImageView;
The code snippet demonstrates the use of FXDNode.getNode(id:String):Node to
retrieve graphics objects using their id property value.
Placing non-orphaned nodes
When working with the FXD API to access objects directly, as shown previously, retrieving
nested objects will return non-orphaned nodes that are part of the FXDNode scene graph
(considered as a parent container). You will get an error if you attempt to move non-orphaned
nodes into another parent container node. The scene graph engine in JavaFX only allows
nodes to have one parent node and will not automatically re-assign parents. To get around
this, the FXD API offers the Duplicator class which automatically returns a cloned,
orphaned copy of the node:
 
Search WWH ::




Custom Search