Java Reference
In-Depth Information
Table 5-8. Functions of the Region Class
Name
Access
Returns
Description
computeMinWidth(height)
Returns the computed minimum width of this Region .
The default is the sum of the left and right insets.
Protected
Double
computeMinHeight(width)
Returns the computed minimum height of the Region .
The default is the sum of the top and bottom insets.
Protected
Double
computePrefWidth(height)
Returns the computed preferred width of the Region .
The default is the sum of the left and right insets plus
the width needed to hold the children when given their
preferred location and size.
Protected
Double
computePrefHeight(width)
Returns the computed preferred height of this Region .
The default is the sum of the top and bottom insets
plus the height needed to hold the children when given
their preferred location and size.
Protected
Double
computeMaxWidth(height)
Returns the computed maximum width of this Region .
The default is Double.MAX_VALUE .
Protected
Double
computeMaxHeight(width)
Returns the computed maximum height of this Region .
The default is Double.MAX_VALUE .
Protected
Double
The defaults returned by the compute functions are fine, except for the preferred width and height, which both
return 0 because we have no children and no insets. To get a nonzero preferred size, we can either override the
computePrefWidth/Height methods or simply call one of the setters for the preferredWidth/Height properties.
The following implementation does the latter.
public class ReversiSquare extends Region {
public ReversiSquare() {
setStyle("-fx-background-color: burlywood");
Light.Distant light = new Light.Distant();
light.setAzimuth(-135);
light.setElevation(30);
setEffect(LightingBuilder.create().light(light).build());
setPrefSize(200, 200);
}
}
To provide styling to the squares in the preceding code, we set the style property, which accepts CSS
properties for the background and borders. Because you cannot specify JavaFX lighting effects in CSS, we use the
LightingBuilder to create a distant lighting effect and set it on the Region .
Caution
on platforms without hardware acceleration of effects, the Lighting effect could significantly affect
performance.
To exercise this class, we create a quick StackPane wrapper holding a single ReversiSquare that resizes with the
scene, as shown in Listing 5-12.
 
Search WWH ::




Custom Search