Java Reference
In-Depth Information
a specific rectangular region within the Group so that the text doesn't appear on the moon or the Earth as it animates
upward. Here's the relevant code snippet:
Group textGroup = new Group(textRef);
textGroup.setLayoutX(50);
textGroup.setLayoutY(180);
textGroup.setClip(new Rectangle(430, 85));
Notice that the Group is located 50 pixels to the right and 180 pixels down from where it would have been located
by default. This is due to the values assigned to the layoutX and layoutY variables of the Group instance. Because this
Group is contained directly by the Scene , its upper-left corner's location is 50 pixels to the right and 180 pixels down
from the upper-left corner of the Scene . Take a look at Figure 1-5 to see this example illustrated as you read the rest of
the explanation.
Figure 1-5. The Scene , Group , Text , and clip illustrated
A Group instance contains instances of Node subclasses by assigning a collection of them to itself via the
children() method. In the previous code snippet, the Group contains a Text instance that has a value assigned to its
layoutY property. Because this Text is contained by a Group , it assumes the two-dimensional space (also called the
coordinate space) of the Group , with the origin of the Text node (0,0) coincident with the top-left corner of the Group .
Assigning a value of 100 to the layoutY property causes the Text to be located 100 pixels down from the top of the
Group , which is just below the bottom of the clip region, thus causing it to be out of view until the animation begins.
Because a value isn't assigned to the layoutX variable, its value is 0 (the default).
The layoutX and layoutY properties of the Group just described are examples of our earlier statement that
nodes contained in a Group will be affected by values assigned to properties of the Group . Another example is setting
the opacity property of a Group instance to 0.5, which causes all of the nodes contained in that Group to become
translucent. If the JavaFX API documentation is handy, look at the properties available in the javafx.scene.Group
class. Then look at the properties available in the javafx.scene.Node class properties, which is where you'll find the
layoutX , layoutY , and opacity variables that are inherited by the Group class.
 
Search WWH ::




Custom Search