JavaFX
- JavaFX Tutorial
- JavaFX Overview
- Your First JavaFX Application
- JavaFX Stage
- JavaFX Scene
- JavaFX Node
- JavaFX Properties
- JavaFX FXML
- JavaFX CSS Styling
- JavaFX ImageView
- JavaFX Text
- JavaFX Fonts
- JavaFX Label
- JavaFX Hyperlink
- JavaFX Button
- JavaFX MenuButton
- JavaFX SplitMenuButton
- JavaFX ToggleButton
- JavaFX RadioButton
- JavaFX CheckBox
- JavaFX ChoiceBox
- JavaFX ComboBox
- JavaFX ListView
- JavaFX DatePicker
- JavaFX ColorPicker
- JavaFX TextField
- JavaFX Slider
- JavaFX PasswordField
- JavaFX TextArea
- JavaFX ToolBar
- JavaFX Tooltip
- JavaFX ProgressBar
- JavaFX FileChooser
- JavaFX DirectoryChooser
- JavaFX TitledPane
- JavaFX Accordion
- JavaFX SplitPane
- JavaFX TabPane
- JavaFX ScrollPane
- JavaFX Group
- JavaFX Region
- JavaFX Pane
- JavaFX HBox
- JavaFX VBox
- JavaFX Separator
- JavaFX FlowPane
- JavaFX TilePane
- JavaFX GridPane
- JavaFX MenuBar
- JavaFX ContexMenu
- JavaFX WebView
- JavaFX PieChart
- JavaFX TableView
- JavaFX TreeView
- JavaFX TreeTableView
- JavaFX HTMLEditor
- JavaFX Pagination
- JavaFX BarChart
- JavaFX StackedBarChart
- JavaFX ScatterChart
- JavaFX LineChart
- JavaFX AreaChart
- JavaFX StackedAreaChart
- JavaFX Color
- JavaFX 2D
- JavaFX Effects
- JavaFX 3D
- JavaFX Transformation
- JavaFX Animation
- JavaFX Media - JavaFX Video and Audio Support
- JavaFX Canvas
- JavaFX Drag and Drop
- JavaFX Concurrency
JavaFX Animation
Jakob Jenkov |
The JavaFX animation support enables you to animate JavaFX shapes and controls, e.g. moving or rotating them. The JavaFX animation support is provided by the JavaFX Timeline class. The Timeline class represents an animation timeline which you can "play". You can add keyframes to the Timeline which the animation features then interpolate between.
JavaFX Animation Example
Here is a basic JavaFX animation example:
import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.util.Duration; /** * A simple JavaFX animation examples. Animates a Circle's X property by * translating (moving) it 200 points over 10 seconds. */ public class AnimationExample extends Application { public static void main(String[] args) { launch(args); } public void start(Stage primaryStage) { Circle circle = new Circle(50, 150, 50, Color.RED); // change circle.translateXProperty from it's current value to 200 KeyValue keyValue = new KeyValue(circle.translateXProperty(), 200); // over the course of 5 seconds KeyFrame keyFrame = new KeyFrame(Duration.seconds(10), keyValue); Timeline timeline = new Timeline(keyFrame); Scene scene = new Scene(new Pane(circle), 300, 250); primaryStage.setScene(scene); primaryStage.show(); timeline.play(); } }
Tweet | |
Jakob Jenkov |