Java Reference
In-Depth Information
Listing 2-4. changeOfScene.css
#stageX, #stageY {
-fx-padding: 3;
-fx-border-color: blue;
-fx-stroke-dash-array: 12 2 4 2;
-fx-border-width: 4;
-fx-border-radius: 5;
}
.emphasized-text {
-fx-font-size: 14pt;
-fx-font-weight: bold;
-fx-font-style: normal;
}
.radio-button *.radio {
-fx-padding: 10;
-fx-background-color: red, yellow;
-fx-background-insets: 0, 5;
-fx-background-radius: 30, 20;
}
.radio-button:focused *.radio {
-fx-background-color: blue, red, yellow;
-fx-background-insets: -5, 0, 5;
-fx-background-radius: 40, 30, 20;
}
Now that you've had some experience with using the Stage and Scene classes, several of the Node subclasses, and
CSS styling, we show you how to handle events that can occur when your JavaFX program is running.
Handling Input Events
So far we've shown you a couple of examples of event handling. For example, we used the onAction event handler to
execute code when a button is clicked. We also used the onCloseRequest event handler of the Stage class to execute
code when the Stage has been requested externally to close. In this section, we explore more of the event handlers
available in JavaFX.
Surveying Mouse, Keyboard, Touch, and Gesture Events and Handlers
Most of the events that occur in JavaFX programs are related to the user manipulating input devices such as a mouse,
a keyboard, or a multitouch screen. To see the available event handlers and their associated event objects, we take
yet another look at the JavaFX API documentation. First, navigate to the javafx.scene.Node class and look for the
properties that begin with the letters “on”. These properties represent the event handlers common to all nodes in
JavaFX. Here is a list of these event handlers in the JavaFX 8 API:
onKeyPressed , onKeyReleased , onKeyTyped
Key event handlers:
onMouseClicked , onMouseDragEntered , onMouseDragExited ,
onMouseDragged , onMouseDragOver , onMouseDragReleased , onMouseEntered , onMouseExited ,
onMouseMoved , onMousePressed , onMouseReleased
Mouse event handlers:
 
Search WWH ::




Custom Search