Java Reference
In-Depth Information
■
a property that is bound cannot be explicitly set. in the code preceding the snippet, the resizable property is set
with the
setResizable()
method
before
the property is bound in the next line.
Tip
Making a Stage Full Screen
Making the
Stage
show in full-screen mode is done by setting the
fullScreen
property of the
Stage
instance to true.
As shown in the following snippet from Listing 2-1, to keep the
fullScreen
property of the
Stage
and the state of the
fullScreen check box synchronized, the
fullScreen
property of the
Stage
instance is updated whenever the selected
property of the
checkBox
changes.
checkBoxFullScreen.selectedProperty().addListener((ov, oldValue, newValue) -> {
stageRef.setFullScreen(checkBoxFullScreen.selectedProperty().getValue());
});
Working with the Bounds of the Stage
The bounds of the
Stage
are represented by its
x
,
y
,
width
, and
height
properties, the values of which can be changed
at will. This is demonstrated in the following snippet from Listing 2-1 where the
Stage
is placed near the top and
centered horizontally on the primary screen after the
Stage
has been initialized.
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2);
stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 4);
We're using the
Screen
class of the
javafx.stage
package to get the dimensions of the primary screen so that the
desired position may be calculated.
■
We intentionally made the
Stage
in figure
2-2
larger than the
Scene
contained within to make the following
point. the width and height of a
Stage
include its decorations (title bar and border), which vary on different platforms.
it is therefore usually better to control the width and height of the
Scene
(we show you how in a bit) and let the
Stage
conform to that size.
Note
Drawing Rounded Rectangles
As pointed out in Chapter 1, you can put rounded corners on a
Rectangle
by specifying the
arcWidth
and
arcHeight
for the corners. The following snippet from Listing 2-1 draws the sky-blue rounded rectangle that becomes the
background for the transparent window example in Figure
2-5
.
Rectangle blue = new Rectangle(250, 350, Color.SKYBLUE);
blue.setArcHeight(50);
blue.setArcWidth(50);
In this snippet, we use the three-argument constructor of
Rectangle
, in which the first two parameters specify
the width and the height of the
Rectangle
. The third parameter defines the fill color of the
Rectangle
.
Search WWH ::
Custom Search