This repository contains a growing collection of JavaFX examples. So far this GitHub repository contains 76 examples. I have plans to add lots more examples in the future, so make sure you star this repository for future reference ;-)
The lists of examples is found here:
The examples come from my JavaFX tutorial series: JavaFX Tutorial.
In general the examples in this repository will attempt to use the latest version of Java and JavaFX. For now the examples are tested with Java 14 and JavaFX 14 (yes, 15 + 15 are latest - will update soon!).
There are 3 options to run the examples.
- Using your IDE (IntelliJ IDEA / Eclipse / Netbeans)
- Using Maven - passing main class to run on the command line
- Using gradle - passing main class to run on the command line
- Using Maven - configuring the main class inside the pom.xml
Some of these are covered in more detail below.
To run the examples from within IntelliJ IDEA you must first create a new project in IntelliJ, and set the root directory to the directory into which you have cloned this Git repository.
Second, you must download JavaFX and unzip the distribution to some directory.
Third, you must add all the JAR files found in the "lib" directory to your project's classpath.
Fourth, you must create a run configuration for the example class you want to run. Add the following JVM args to that run configuration:
--module-path C:\data\downloads\javafx\javafx-sdk-14\lib --add-modules javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web
Make sure that the --module-path points to the directory you unzipped your downloaded JavaFX distribution to (meaning the "lib" dir within that JavaFX distribution dir - as shown above).
Instead of creating run configuration for each example class you can create a run configuration for the ExampleRunner class(based on maven or gradle nature. Both are supported using wrappers so you don't need to have any of them on you system and you can choose to use the one you prefer), and then from inside the ExampleRunner class, call the example class you want to run - by changing the main() method inside the ExampleRunner class. For instance, add the following line to the ExampleRunner class main() method and then run ExampleRunner main
ButtonExample.main(args);
You can use maven and pass the example class you want to add. for example to run WebViewExample you can run
./mvnw compile exec:java -Dexec.args="com.jenkov.javafx.webview.WebViewExample"
You can use gradle and pass the example class you want to add. for example to run WebViewExample you can run
./gradlew run --args="com.jenkov.javafx.webview.WebViewExample"
You can use Maven and edit the pom.xml file and change "mainClass" of openjfx plugin configuration and select the example you want then run
./mvnw clean javafx:run
If you have any suggestions for missing examples, create a GitHub issue in this repo, and / or ping me on Twitter (@jjenkov) or LinkedIn (Jakob Jenkov).
- Accordion Example
- Animation Example
- Button Examples
- Canvas Example
- ChoiceBox Example
- Color Example
- ColorPicker Example
- ComboBox Example
- Concurrency Example
- ContextMenu Example
- DirectoryChooser Example
- FileChooser Example
- Font Example
- FXML Example
- HTMLEditor Example Hyperlink Examples
- ImageView Example
- Label Examples
- Media Example
- MenuButton Examples
- Pagination Example
- ProgressBar Example
- Properties Example
- Scene Cursor Example
- ScrollPane Example
- Separator Example
- Slider Example
- SplitMenuButton Example
- SplitPane Example
- Stage Examples
- TabPane Example
- TableView Examples
- Text Example
- TextArea Example
- TextField Example
- TitledPane Example
- ToggleButton Examples
- ToolBar Example
- ToolTip Example
- TreeTableView Example
- TreeView Example
- VBox Example
- WebView Examples
- WebView Example
- WebView JavaScript Integration Example
- WebView Mouse Wheel Zoom Example (Mouse wheel zoom code provided by Friedhold Matz (@FriedholdMatz on Twitter))
- 2D Examples
- 3D Examples
- Transformations Examples
- Drag and Drop Examples