├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── assets ├── fxml │ ├── button-example.fxml │ └── hello-world.fxml ├── media │ ├── Golden-48569.mp4 │ ├── Golden-48569.mp4.license.txt │ ├── abstract-5719221_640.jpg │ ├── abstract-5719221_640.jpg.license.txt │ ├── iconmonstr-user-1-32.png │ └── iconmonstr-user-1-32.png.license.txt └── webview │ └── stylesheet.css ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── javafx-bugs-missing-features-questions.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── settings.gradle └── src └── main └── java └── com └── jenkov └── javafx ├── ExampleRunner.java ├── ExampleRunnerFromMaven.java ├── accordion └── AccordionExample.java ├── animation └── AnimationExample.java ├── apps └── AppExample.java ├── button ├── ButtonDefaultAndCancelModesExample.java ├── ButtonExample.java ├── ButtonFXMLController.java ├── ButtonFXMLExample.java ├── ButtonFontExample.java ├── ButtonTransformationExample.java └── DisabledButtonExample.java ├── canvas └── CanvasExample.java ├── choicebox └── ChoiceBoxExample.java ├── color └── ColorExample.java ├── colorpicker └── ColorPickerExample.java ├── combobox └── ComboBoxExample.java ├── concurrency └── ConcurrencyExample.java ├── contextmenu └── ContextMenuExample.java ├── directorychooser └── DirectoryChooserExample.java ├── draganddrop ├── DragAndDropExample.java └── DragAndDropExampleDraft.java ├── filechooser └── FileChooserExample.java ├── font └── FontExample.java ├── fxml ├── FXMLExample.java └── MyFxmlController.java ├── gfx2d └── Gfx2DExample.java ├── gfx3d ├── Gfx3DExample.java ├── Gfx3DExampleDraft.java ├── Gfx3DExperiments.java └── Gfx3DUtil.java ├── htmleditor └── HtmlEditorExample.java ├── hyperlink ├── HyperlinkChangeTextExample.java ├── HyperlinkExample.java └── HyperlinkFontExample.java ├── imageview └── ImageViewExample.java ├── label ├── LabelChangeTextExample.java ├── LabelExample.java └── LabelFontExample.java ├── layout ├── AutoResponsiveLayout.java └── AutoResponsiveLayoutExample.java ├── media └── MediaExample.java ├── menubutton ├── MenuButtonExample.java ├── MenuButtonFontExample.java └── MenuButtonIconExample.java ├── pagination └── PaginationExample.java ├── progressbar └── ProgressBarExample.java ├── properties └── PropertyExample.java ├── scene └── SceneCursorExample.java ├── scrollpane └── ScrollPaneExample.java ├── separator └── SeparatorExample.java ├── slider └── SliderExample.java ├── splitmenubutton ├── SplitMenuButtonExample.java └── SplitMenuButtonFontExample.java ├── splitpane └── SplitPaneExample.java ├── stage ├── AutoShutDownExample.java ├── FullScreenStageExample.java ├── MultipleStagesExample.java ├── MultipleStagesModalExample.java ├── StageDecorationExample.java ├── StageExample.java └── StageKeyboardEventsExample.java ├── tableview ├── Customer.java ├── Person.java ├── TableViewCustomRenderingExample.java ├── TableViewEditableExample.java ├── TableViewExample.java ├── TableViewMapDataItemsExample.java ├── TableViewNestedColumnsExample.java └── TableViewSelectionModelExample.java ├── tabpane └── TabPaneExample.java ├── text └── TextExample.java ├── textarea └── TextAreaExample.java ├── textfield └── TextFieldExample.java ├── titledpane └── TitledPaneExample.java ├── togglebutton ├── ToggleButtonExample.java └── ToggleButtonFontExample.java ├── toolbar └── ToolBarExample.java ├── tooltip └── ToolTipExample.java ├── transformations ├── RotateTransformationExample.java ├── ScaleTransformationExample.java ├── TransformationsExample.java └── TranslateTransformationExample.java ├── treetableview ├── Car.java └── TreeTableViewExample.java ├── treeview └── TreeViewExample.java ├── vbox └── VBoxExample.java └── webview ├── WebViewExample.java ├── WebViewJavaScriptIntegrationExample.java └── WebViewMouseWheelZoomExample.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | 3 | *.iml 4 | 5 | target/ 6 | out/ 7 | 8 | build/ 9 | bin/ 10 | .classpath 11 | .project 12 | .settings 13 | 14 | .gradle 15 | 16 | notes.txt -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjenkov/javafx-examples/20eee2b70b59fadcc3a5ebff0e8da0307dfe9416/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaFX Examples 2 | This repository contains a growing collection of JavaFX examples. So far this GitHub repository contains 76 examples. 3 | I have plans to add lots more examples in the future, so make sure you star this repository for future reference ;-) 4 | 5 | 6 | The lists of examples is found here: 7 | 8 | - [JavaFX Basic Examples](#javafx-basic-examples) 9 | - [JavaFX Advanced Examples](#javafx-advanced-examples) 10 | 11 | ## JavaFX Tutorial 12 | The examples come from my JavaFX tutorial series: [JavaFX Tutorial](http://tutorials.jenkov.com). 13 | 14 | ## Java + JavaFX Version Used 15 | In general the examples in this repository will attempt to use the latest version of Java and JavaFX. 16 | For now the examples are tested with Java 14 and JavaFX 14 (yes, 15 + 15 are latest - will update soon!). 17 | 18 | ## Running the Examples 19 | There are 3 options to run the examples. 20 | 21 | - Using your IDE (IntelliJ IDEA / Eclipse / Netbeans) 22 | - Using Maven - passing main class to run on the command line 23 | - Using gradle - passing main class to run on the command line 24 | - Using Maven - configuring the main class inside the pom.xml 25 | 26 | Some of these are covered in more detail below. 27 | 28 | ### Run the Examples in IntelliJ Idea(needs pre-downloaded javafx modules) 29 | To run the examples from within IntelliJ IDEA you must first create a new project in IntelliJ, and set the root 30 | directory to the directory into which you have cloned this Git repository. 31 | 32 | Second, you must download JavaFX and unzip the distribution to some directory. 33 | 34 | Third, you must add all the JAR files found in the "lib" directory to your project's classpath. 35 | 36 | Fourth, you must create a run configuration for the example class you want to run. Add the following 37 | JVM args to that run configuration: 38 | 39 | --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 40 | 41 | 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). 42 | 43 | ### Run in IDE - alternative 44 | 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 45 | ExampleRunner class, call the example class you want to run - by changing the main() method inside the ExampleRunner class. For instance, 46 | add the following line to the ExampleRunner class main() method and then run ExampleRunner main 47 | 48 | ButtonExample.main(args); 49 | 50 | 51 | ### Run via Maven - Passing Main Class as Argument to Maven 52 | You can use maven and pass the example class you want to add. for example to run WebViewExample you can run 53 | 54 | ./mvnw compile exec:java -Dexec.args="com.jenkov.javafx.webview.WebViewExample" 55 | 56 | ### Run via Gradle - Passing Main Class as Argument to Gradle 57 | You can use gradle and pass the example class you want to add. for example to run WebViewExample you can run 58 | 59 | ./gradlew run --args="com.jenkov.javafx.webview.WebViewExample" 60 | 61 | ### Run via Maven 62 | 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 63 | 64 | ./mvnw clean javafx:run 65 | 66 | 67 | ## Suggestions 68 | If you have any suggestions for missing examples, create a GitHub issue in this repo, and / or ping me on 69 | Twitter (@jjenkov) or LinkedIn (Jakob Jenkov). 70 | 71 | 72 | # JavaFX Basic Examples 73 | 74 | - [Accordion Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/accordion/AccordionExample.java) 75 | - [Animation Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/animation/AnimationExample.java) 76 | - Button Examples 77 | - [Button Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/button/ButtonExample.java) 78 | - [Button Font Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/button/ButtonFontExample.java) 79 | - [Disabled Button Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/button/DisabledButtonExample.java) 80 | - [Normal, Default and Cancel Mode Button Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/button/ButtonDefaultAndCancelModesExample.java) 81 | - [Button FXML Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/button/ButtonFXMLExample.java) 82 | - [Button Transformation Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/button/ButtonTransformationExample.java) 83 | - [Canvas Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/canvas/CanvasExample.java) 84 | - [ChoiceBox Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/choicebox/ChoiceBoxExample.java) 85 | - [Color Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/color/ColorExample.java) 86 | - [ColorPicker Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/colorpicker/ColorPickerExample.java) 87 | - [ComboBox Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/combobox/ComboBoxExample.java) 88 | - [Concurrency Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/concurrency/ConcurrencyExample.java) 89 | - [ContextMenu Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/contextmenu/ContextMenuExample.java) 90 | - [DirectoryChooser Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/directorychooser/DirectoryChooserExample.java) 91 | - [FileChooser Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/filechooser/FileChooserExample.java) 92 | - [Font Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/font/FontExample.java) 93 | - [FXML Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/fxml/FXMLExample.java) 94 | - [HTMLEditor Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/htmleditor/HtmlEditorExample.java) 95 | Hyperlink Examples 96 | - [Hyperlink Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/hyperlink/HyperlinkExample.java) 97 | - [Hyperlink Font Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/hyperlink/HyperlinkFontExample.java) 98 | - [Hyperlink Change Text Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/hyperlink/HyperlinkChangeTextExample.java) 99 | - [ImageView Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/imageview/ImageViewExample.java) 100 | - Label Examples 101 | - [Label Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/label/LabelExample.java) 102 | - [Label Font Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/label/LabelFontExample.java) 103 | - [Label Change Text Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/label/LabelChangeTextExample.java) 104 | - [Media Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/media/MediaExample.java) 105 | - MenuButton Examples 106 | - [MenuButton Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/menubutton/MenuButtonExample.java) 107 | - [MenuButton Font Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/menubutton/MenuButtonFontExample.java) 108 | - [MenuButton Icon Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/menubutton/MenuButtonIconExample.java) 109 | - [Pagination Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/pagination/PaginationExample.java) 110 | - [ProgressBar Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/progressbar/ProgressBarExample.java) 111 | - [Properties Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/properties/PropertyExample.java) 112 | - [Scene Cursor Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/scene/SceneCursorExample.java) 113 | - [ScrollPane Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/scrollpane/ScrollPaneExample.java) 114 | - [Separator Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/separator/SeparatorExample.java) 115 | - [Slider Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/slider/SliderExample.java) 116 | - [SplitMenuButton Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/splitmenubutton/SplitMenuButtonExample.java) 117 | - [SplitPane Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/splitpane/SplitPaneExample.java) 118 | - Stage Examples 119 | - [Stage Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/StageExample.java) 120 | - [Stage Decoration Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/StageDecorationExample.java) 121 | - [Multiple Stages Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/MultipleStagesExample.java) 122 | - [Multiple Stages Modal Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/MultipleStagesModalExample.java) 123 | - [Full Screen Stage Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/FullScreenStageExample.java) 124 | - [Auto Shutdown Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/AutoShutDownExample.java) 125 | - [Keyboard Events Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/stage/StageKeyboardEventsExample.java) 126 | - [TabPane Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tabpane/TabPaneExample.java) 127 | - TableView Examples 128 | - [TableView Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tableview/TableViewExample.java) 129 | - [TableView Editable Column Cells Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tableview/TableViewEditableExample.java) 130 | - [TableView Nested Columns Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tableview/TableViewNestedColumnsExample.java) 131 | - [TableView Selection Model Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tableview/TableViewSelectionModelExample.java) 132 | - [TableView Custom Rendering Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tableview/TableViewCustomRenderingExample.java) 133 | - [TableView Map as Data Items Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tableview/TableViewMapDataItemsExample.java) 134 | - [Text Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/text/TextExample.java) 135 | - [TextArea Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/textarea/TextAreaExample.java) 136 | - [TextField Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/textfield/TextFieldExample.java) 137 | - [TitledPane Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/titledpane/TitledPaneExample.java) 138 | - ToggleButton Examples 139 | - [ToggleButton Example](https://github.com/jjenkov/javafx-example/blob/main/src/main/java/com/jenkov/javafx/togglebutton/ToggleButtonExample.java) 140 | - [ToggleButton Font Example](https://github.com/jjenkov/javafx-example/blob/main/src/main/java/com/jenkov/javafx/togglebutton/ToggleButtonFontExample.java) 141 | - [ToolBar Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/toolbar/ToolBarExample.java) 142 | - [ToolTip Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/tooltip/ToolTipExample.java) 143 | - [TreeTableView Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/treetableview/TreeTableViewExample.java) 144 | - [TreeView Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/treeview/TreeViewExample.java) 145 | - [VBox Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/vbox/VBoxExample.java) 146 | - WebView Examples 147 | - [WebView Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewExample.java) 148 | - [WebView JavaScript Integration Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewJavaScriptIntegrationExample.java) 149 | - [WebView Mouse Wheel Zoom Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewMouseWheelZoomExample.java) 150 | (Mouse wheel zoom code provided by Friedhold Matz (@FriedholdMatz on Twitter)) 151 | - 2D Examples 152 | - [2D Basics Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/gfx2d/Gfx2DExample.java) 153 | - 3D Examples 154 | - [3D Basics Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/gfx3d/Gfx3DExample.java) 155 | - Transformations Examples 156 | - [Transformations Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/transformations/TransformationsExample.java) 157 | - [Translate Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/transformations/TranslateTransformationsExample.java) 158 | - [Rotate Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/transformations/RotateTransformationsExample.java) 159 | - [Scale Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/transformations/ScaleTransformationsExample.java) 160 | - Drag and Drop Examples 161 | - [Drag and Drop Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/draganddrop/DragAndDropExample.java) 162 | 163 | 164 | 165 | # JavaFX Advanced Examples 166 | - [Auto-responsive Layout Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/layout/AutoResponsiveLayoutExample.java) 167 | 168 | 169 | -------------------------------------------------------------------------------- /assets/fxml/button-example.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ", "text/html"); 45 | 46 | webEngine.setUserAgent("MyApp Web Browser 1.0"); 47 | 48 | webEngine.getLoadWorker().stateProperty().addListener( 49 | new ChangeListener() { 50 | @Override 51 | public void changed(ObservableValue observable, Object oldValue, Object newValue) { 52 | System.out.println("oldValue: " + oldValue); 53 | System.out.println("newValue: " + newValue); 54 | 55 | if (newValue != Worker.State.SUCCEEDED) { 56 | return; 57 | } 58 | System.out.println("Succeeded!"); 59 | String hello = (String) webEngine.executeScript("hmm()"); 60 | System.out.println("hello: " + hello); 61 | 62 | JSObject window = (JSObject) webEngine.executeScript("window"); 63 | window.setMember("myObject", new MyObject()); 64 | 65 | Document document = webEngine.getDocument(); 66 | } 67 | } 68 | ); 69 | 70 | String result = (String) webEngine.executeScript("hmm()"); 71 | System.out.println(result); 72 | 73 | VBox vBox = new VBox(webView); 74 | Scene scene = new Scene(vBox, 960, 600); 75 | 76 | primaryStage.setScene(scene); 77 | primaryStage.show(); 78 | 79 | 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/main/java/com/jenkov/javafx/webview/WebViewMouseWheelZoomExample.java: -------------------------------------------------------------------------------- 1 | package com.jenkov.javafx.webview; 2 | 3 | import javafx.application.Application; 4 | import javafx.beans.value.ChangeListener; 5 | import javafx.beans.value.ObservableValue; 6 | import javafx.collections.ObservableList; 7 | import javafx.concurrent.Worker; 8 | import javafx.scene.Scene; 9 | import javafx.scene.input.ScrollEvent; 10 | import javafx.scene.layout.VBox; 11 | import javafx.scene.web.WebEngine; 12 | import javafx.scene.web.WebHistory; 13 | import javafx.scene.web.WebView; 14 | import javafx.stage.Stage; 15 | import netscape.javascript.JSObject; 16 | import org.w3c.dom.Document; 17 | 18 | import java.util.Date; 19 | import java.util.Iterator; 20 | 21 | /** 22 | * This WebView example shows how to enable a zoom function by 23 | * scrolling the mouse wheel while holding CTRL down. The mouse wheel zoom code 24 | * was provided by Friedhold Matz @FriedholdMatz : 25 | 26 | // --- CTRL-Scroll Zooming --- 27 | webView.addEventFilter(ScrollEvent.SCROLL, (ScrollEvent e) -> { 28 | double deltaY = e.getDeltaY(); 29 | if (e.isControlDown() && deltaY > 0) { 30 | webView.setZoom(webView.getZoom() * 1.1); 31 | e.consume(); 32 | } else if (e.isControlDown() && deltaY < 0) { 33 | webView.setZoom(webView.getZoom() / 1.1); 34 | e.consume(); 35 | } 36 | }); 37 | */ 38 | 39 | public class WebViewMouseWheelZoomExample extends Application { 40 | 41 | public static class MyObject { 42 | 43 | public void doIt() { 44 | System.out.println("doIt() called"); 45 | } 46 | } 47 | 48 | public static void main(String[] args) { 49 | launch(args); 50 | } 51 | 52 | public void start(Stage primaryStage) { 53 | primaryStage.setTitle("JavaFX WebView Example"); 54 | 55 | WebView webView = new WebView(); 56 | 57 | WebEngine webEngine = webView.getEngine(); 58 | 59 | //webEngine.load("http://tutorials.jenkov.com"); 60 | webEngine.loadContent("Hello World!", "text/html"); 61 | 62 | webView.addEventFilter(ScrollEvent.SCROLL, (ScrollEvent e) -> { 63 | double deltaY = e.getDeltaY(); 64 | if (e.isControlDown() && deltaY > 0) { 65 | webView.setZoom(webView.getZoom() * 1.1); 66 | e.consume(); 67 | } else if (e.isControlDown() && deltaY < 0) { 68 | webView.setZoom(webView.getZoom() / 1.1); 69 | e.consume(); 70 | } 71 | }); 72 | 73 | VBox vBox = new VBox(webView); 74 | Scene scene = new Scene(vBox, 960, 600); 75 | 76 | primaryStage.setScene(scene); 77 | primaryStage.show(); 78 | 79 | 80 | } 81 | 82 | } --------------------------------------------------------------------------------