├── .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 |
7 |
8 |
--------------------------------------------------------------------------------
/assets/fxml/hello-world.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/assets/media/Golden-48569.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jjenkov/javafx-examples/20eee2b70b59fadcc3a5ebff0e8da0307dfe9416/assets/media/Golden-48569.mp4
--------------------------------------------------------------------------------
/assets/media/Golden-48569.mp4.license.txt:
--------------------------------------------------------------------------------
1 | The video file Golden-48569.mp4 is downloaded from the Pixabay.com free, royalty free image, photo and video service.
2 |
3 | I have included this file in the GitHub repo *only* for use in the JavaFX media examples.
4 |
5 | Please do not redistribute this file for any purpose! If you want to use this file, please go to Pixabay.com
6 | and download it from there:
7 |
8 | https://pixabay.com/videos/golden-particles-overlay-decoration-48569/
--------------------------------------------------------------------------------
/assets/media/abstract-5719221_640.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jjenkov/javafx-examples/20eee2b70b59fadcc3a5ebff0e8da0307dfe9416/assets/media/abstract-5719221_640.jpg
--------------------------------------------------------------------------------
/assets/media/abstract-5719221_640.jpg.license.txt:
--------------------------------------------------------------------------------
1 | The image file abstract-5719221_640.jpg is downloaded from the Pixabay.com free, royalty free image, photo and video service.
2 |
3 | I have included this file in the GitHub repo *only* for use in the JavaFX examples.
4 |
5 | Please do not redistribute this file for any purpose! If you want to use this file, please go to Pixabay.com
6 | and download it from there:
7 |
8 | https://pixabay.com/illustrations/abstract-dust-background-wallpaper-5719221/
--------------------------------------------------------------------------------
/assets/media/iconmonstr-user-1-32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jjenkov/javafx-examples/20eee2b70b59fadcc3a5ebff0e8da0307dfe9416/assets/media/iconmonstr-user-1-32.png
--------------------------------------------------------------------------------
/assets/media/iconmonstr-user-1-32.png.license.txt:
--------------------------------------------------------------------------------
1 | The icon file iconmonstr-user-1-32.png is downloaded from the iconmonstr.com free, royalty free icon service.
2 |
3 | I have included this file in the GitHub repo *only* for use in the JavaFX icon and graphics examples.
4 |
5 | Please do not redistribute this file for any purpose! If you want to use this file, please go to iconmonstr.com
6 | and download it from there:
7 |
8 | https://iconmonstr.com/user-1-png/
--------------------------------------------------------------------------------
/assets/webview/stylesheet.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: arial;
3 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | *
4 | * This generated file contains a sample Java Library project to get you started.
5 | * For more details take a look at the Java Libraries chapter in the Gradle
6 | * User Manual available at https://docs.gradle.org/6.4.1/userguide/java_library_plugin.html
7 | */
8 |
9 | plugins {
10 | id 'eclipse'
11 | id 'idea'
12 | id 'application'
13 | id 'org.openjfx.javafxplugin' version '0.0.9'
14 | }
15 |
16 | // if you want to use remote debuging uncomment this.
17 | /*
18 | run {
19 | jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005'
20 | standardInput = System.in
21 | }*/
22 |
23 | mainClassName = 'com.jenkov.javafx.ExampleRunnerFromMaven'
24 |
25 | repositories {
26 | // Use jcenter for resolving dependencies.
27 | // You can declare any Maven/Ivy/file repository here.
28 | jcenter()
29 | google()
30 | mavenCentral()
31 | }
32 |
33 | run {
34 | standardInput = System.in
35 | }
36 |
37 | javafx {
38 | version = "14.0.2"
39 | modules = [ 'javafx.base', 'javafx.swing', 'javafx.graphics', 'javafx.controls', 'javafx.fxml', 'javafx.media', 'javafx.web' ]
40 | }
41 |
42 | dependencies {
43 | }
44 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jjenkov/javafx-examples/20eee2b70b59fadcc3a5ebff0e8da0307dfe9416/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jun 09 18:27:32 IRDT 2020
2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
3 | distributionBase=GRADLE_USER_HOME
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto init
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto init
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :init
68 | @rem Get command-line arguments, handling Windows variants
69 |
70 | if not "%OS%" == "Windows_NT" goto win9xME_args
71 |
72 | :win9xME_args
73 | @rem Slurp the command line arguments.
74 | set CMD_LINE_ARGS=
75 | set _SKIP=2
76 |
77 | :win9xME_args_slurp
78 | if "x%~1" == "x" goto execute
79 |
80 | set CMD_LINE_ARGS=%*
81 |
82 | :execute
83 | @rem Setup the command line
84 |
85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
86 |
87 |
88 | @rem Execute Gradle
89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
90 |
91 | :end
92 | @rem End local scope for the variables with windows NT shell
93 | if "%ERRORLEVEL%"=="0" goto mainEnd
94 |
95 | :fail
96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
97 | rem the _cmd.exe /c_ return code!
98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
99 | exit /b 1
100 |
101 | :mainEnd
102 | if "%OS%"=="Windows_NT" endlocal
103 |
104 | :omega
105 |
--------------------------------------------------------------------------------
/javafx-bugs-missing-features-questions.md:
--------------------------------------------------------------------------------
1 | # JavaFX Bugs
2 | A list of JavaFX bugs I have found while making these JavaFX examples.
3 |
4 | - When a MenuButton is moved from a monitor with one pixel density to another monitor with a different pixel density
5 | (e.g. a labtop monitor to a bigger, externally attached monitor), the menu items showing when the MenuButton is
6 | activated no longer align with the button. There is a vertical gap in between the MenuButton and the menu items.
7 |
8 |
9 |
10 | - How to set the font of a ChoiceBox and ComboBox? By setting a custom cell factory?
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Mingw, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | fi
118 |
119 | if [ -z "$JAVA_HOME" ]; then
120 | javaExecutable="`which javac`"
121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
122 | # readlink(1) is not available as standard on Solaris 10.
123 | readLink=`which readlink`
124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
125 | if $darwin ; then
126 | javaHome="`dirname \"$javaExecutable\"`"
127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
128 | else
129 | javaExecutable="`readlink -f \"$javaExecutable\"`"
130 | fi
131 | javaHome="`dirname \"$javaExecutable\"`"
132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
133 | JAVA_HOME="$javaHome"
134 | export JAVA_HOME
135 | fi
136 | fi
137 | fi
138 |
139 | if [ -z "$JAVACMD" ] ; then
140 | if [ -n "$JAVA_HOME" ] ; then
141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
142 | # IBM's JDK on AIX uses strange locations for the executables
143 | JAVACMD="$JAVA_HOME/jre/sh/java"
144 | else
145 | JAVACMD="$JAVA_HOME/bin/java"
146 | fi
147 | else
148 | JAVACMD="`which java`"
149 | fi
150 | fi
151 |
152 | if [ ! -x "$JAVACMD" ] ; then
153 | echo "Error: JAVA_HOME is not defined correctly." >&2
154 | echo " We cannot execute $JAVACMD" >&2
155 | exit 1
156 | fi
157 |
158 | if [ -z "$JAVA_HOME" ] ; then
159 | echo "Warning: JAVA_HOME environment variable is not set."
160 | fi
161 |
162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
163 |
164 | # traverses directory structure from process work directory to filesystem root
165 | # first directory with .mvn subdirectory is considered project base directory
166 | find_maven_basedir() {
167 |
168 | if [ -z "$1" ]
169 | then
170 | echo "Path not specified to find_maven_basedir"
171 | return 1
172 | fi
173 |
174 | basedir="$1"
175 | wdir="$1"
176 | while [ "$wdir" != '/' ] ; do
177 | if [ -d "$wdir"/.mvn ] ; then
178 | basedir=$wdir
179 | break
180 | fi
181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
182 | if [ -d "${wdir}" ]; then
183 | wdir=`cd "$wdir/.."; pwd`
184 | fi
185 | # end of workaround
186 | done
187 | echo "${basedir}"
188 | }
189 |
190 | # concatenates all lines of a file
191 | concat_lines() {
192 | if [ -f "$1" ]; then
193 | echo "$(tr -s '\n' ' ' < "$1")"
194 | fi
195 | }
196 |
197 | BASE_DIR=`find_maven_basedir "$(pwd)"`
198 | if [ -z "$BASE_DIR" ]; then
199 | exit 1;
200 | fi
201 |
202 | ##########################################################################################
203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
204 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
205 | ##########################################################################################
206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
207 | if [ "$MVNW_VERBOSE" = true ]; then
208 | echo "Found .mvn/wrapper/maven-wrapper.jar"
209 | fi
210 | else
211 | if [ "$MVNW_VERBOSE" = true ]; then
212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
213 | fi
214 | if [ -n "$MVNW_REPOURL" ]; then
215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
216 | else
217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
218 | fi
219 | while IFS="=" read key value; do
220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
221 | esac
222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
223 | if [ "$MVNW_VERBOSE" = true ]; then
224 | echo "Downloading from: $jarUrl"
225 | fi
226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
227 | if $cygwin; then
228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
229 | fi
230 |
231 | if command -v wget > /dev/null; then
232 | if [ "$MVNW_VERBOSE" = true ]; then
233 | echo "Found wget ... using wget"
234 | fi
235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
236 | wget "$jarUrl" -O "$wrapperJarPath"
237 | else
238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
239 | fi
240 | elif command -v curl > /dev/null; then
241 | if [ "$MVNW_VERBOSE" = true ]; then
242 | echo "Found curl ... using curl"
243 | fi
244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
245 | curl -o "$wrapperJarPath" "$jarUrl" -f
246 | else
247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
248 | fi
249 |
250 | else
251 | if [ "$MVNW_VERBOSE" = true ]; then
252 | echo "Falling back to using Java to download"
253 | fi
254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
255 | # For Cygwin, switch paths to Windows format before running javac
256 | if $cygwin; then
257 | javaClass=`cygpath --path --windows "$javaClass"`
258 | fi
259 | if [ -e "$javaClass" ]; then
260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
261 | if [ "$MVNW_VERBOSE" = true ]; then
262 | echo " - Compiling MavenWrapperDownloader.java ..."
263 | fi
264 | # Compiling the Java class
265 | ("$JAVA_HOME/bin/javac" "$javaClass")
266 | fi
267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
268 | # Running the downloader
269 | if [ "$MVNW_VERBOSE" = true ]; then
270 | echo " - Running MavenWrapperDownloader.java ..."
271 | fi
272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
273 | fi
274 | fi
275 | fi
276 | fi
277 | ##########################################################################################
278 | # End of extension
279 | ##########################################################################################
280 |
281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
282 | if [ "$MVNW_VERBOSE" = true ]; then
283 | echo $MAVEN_PROJECTBASEDIR
284 | fi
285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
286 |
287 | # For Cygwin, switch paths to Windows format before running java
288 | if $cygwin; then
289 | [ -n "$M2_HOME" ] &&
290 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
291 | [ -n "$JAVA_HOME" ] &&
292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
293 | [ -n "$CLASSPATH" ] &&
294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
295 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
297 | fi
298 |
299 | # Provide a "standardized" way to retrieve the CLI args that will
300 | # work with both Windows and non-Windows executions.
301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
302 | export MAVEN_CMD_LINE_ARGS
303 |
304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
305 |
306 | exec "$JAVACMD" \
307 | $MAVEN_OPTS \
308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
311 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
124 |
125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
127 | )
128 |
129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
131 | if exist %WRAPPER_JAR% (
132 | if "%MVNW_VERBOSE%" == "true" (
133 | echo Found %WRAPPER_JAR%
134 | )
135 | ) else (
136 | if not "%MVNW_REPOURL%" == "" (
137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
138 | )
139 | if "%MVNW_VERBOSE%" == "true" (
140 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
141 | echo Downloading from: %DOWNLOAD_URL%
142 | )
143 |
144 | powershell -Command "&{"^
145 | "$webclient = new-object System.Net.WebClient;"^
146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148 | "}"^
149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150 | "}"
151 | if "%MVNW_VERBOSE%" == "true" (
152 | echo Finished downloading %WRAPPER_JAR%
153 | )
154 | )
155 | @REM End of extension
156 |
157 | @REM Provide a "standardized" way to retrieve the CLI args that will
158 | @REM work with both Windows and non-Windows executions.
159 | set MAVEN_CMD_LINE_ARGS=%*
160 |
161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
162 | if ERRORLEVEL 1 goto error
163 | goto end
164 |
165 | :error
166 | set ERROR_CODE=1
167 |
168 | :end
169 | @endlocal & set ERROR_CODE=%ERROR_CODE%
170 |
171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
175 | :skipRcPost
176 |
177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
179 |
180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
181 |
182 | exit /B %ERROR_CODE%
183 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 | 4.0.0
7 | com.jenkov
8 | javafx-examples
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | UTF-8
13 | UTF-8
14 |
15 | 15.0.1
16 | com.jenkov.javafx.stage.MultipleStagesModalExample
17 |
18 |
19 |
20 |
21 |
22 | org.openjfx
23 | javafx-base
24 | ${javafx.version}
25 |
26 |
27 | org.openjfx
28 | javafx-controls
29 | ${javafx.version}
30 |
31 |
32 | org.openjfx
33 | javafx-graphics
34 | ${javafx.version}
35 |
36 |
37 | org.openjfx
38 | javafx-media
39 | ${javafx.version}
40 |
41 |
42 | org.openjfx
43 | javafx-swing
44 | ${javafx.version}
45 |
46 |
47 | org.openjfx
48 | javafx-fxml
49 | ${javafx.version}
50 |
51 |
52 | org.openjfx
53 | javafx-web
54 | ${javafx.version}
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | org.codehaus.mojo
63 | exec-maven-plugin
64 | 3.0.0
65 |
66 | com.jenkov.javafx.ExampleRunnerFromMaven
67 |
68 |
69 |
70 |
71 | org.openjfx
72 | javafx-maven-plugin
73 | 0.0.5
74 |
75 | ${mainClass}
76 |
77 |
78 |
79 |
80 | maven-compiler-plugin
81 | 3.8.1
82 |
83 | 14
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | *
4 | * The settings file is used to specify which projects to include in your build.
5 | *
6 | * Detailed information about configuring a multi-project build in Gradle can be found
7 | * in the user manual at https://docs.gradle.org/6.4.1/userguide/multi_project_builds.html
8 | */
9 | rootProject.name = 'javafx-examples'
10 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/ExampleRunner.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx;
2 |
3 | public class ExampleRunner {
4 |
5 | public static void main(final String[] args) {
6 | // class each example main method you want from here and run this class's main from your IDE:
7 | // for example to run ButtonExample uncomment the line below and run this class
8 | // ButtonExample.main(args);
9 |
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/ExampleRunnerFromMaven.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx;
2 |
3 | import java.lang.reflect.InvocationTargetException;
4 | import java.util.Arrays;
5 |
6 | import com.jenkov.javafx.button.ButtonExample;
7 | import com.jenkov.javafx.webview.WebViewExample;
8 |
9 | public class ExampleRunnerFromMaven {
10 |
11 | public static void main(String[] args) {
12 | try {
13 | String[] params = Arrays.copyOfRange(args, 1, args.length);
14 | Class.forName(args[0]).getMethod("main", String[].class)
15 | .invoke(null, (Object) params);
16 | } catch (IllegalAccessException | IllegalArgumentException
17 | | InvocationTargetException | NoSuchMethodException
18 | | SecurityException | ClassNotFoundException e) {
19 | // TODO Auto-generated catch block
20 | e.printStackTrace();
21 | }
22 |
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/accordion/AccordionExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.accordion;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Accordion;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.TitledPane;
8 | import javafx.scene.layout.VBox;
9 | import javafx.stage.Stage;
10 |
11 | public class AccordionExample extends Application {
12 |
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | public void start(Stage primaryStage) {
18 |
19 | Accordion accordion = new Accordion();
20 |
21 | TitledPane pane1 = new TitledPane("Boats" , new Label("Show all boats available"));
22 | TitledPane pane2 = new TitledPane("Cars" , new Label("Show all cars available"));
23 | TitledPane pane3 = new TitledPane("Planes", new Label("Show all planes available"));
24 |
25 | accordion.getPanes().add(pane1);
26 | accordion.getPanes().add(pane2);
27 | accordion.getPanes().add(pane3);
28 |
29 | VBox vBox = new VBox(accordion);
30 | Scene scene = new Scene(vBox);
31 |
32 | primaryStage.setScene(scene);
33 |
34 | primaryStage.show();
35 | }
36 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/animation/AnimationExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.animation;
2 |
3 | import javafx.animation.KeyFrame;
4 | import javafx.animation.KeyValue;
5 | import javafx.animation.Timeline;
6 | import javafx.application.Application;
7 | import javafx.scene.Scene;
8 | import javafx.scene.layout.Pane;
9 | import javafx.scene.paint.Color;
10 | import javafx.scene.shape.Circle;
11 | import javafx.stage.Stage;
12 | import javafx.util.Duration;
13 |
14 | /**
15 | * A simple JavaFX animation examples. Animates a Circle's X property by translating (moving) it 200 points
16 | * over 10 seconds.
17 | */
18 |
19 | public class AnimationExample extends Application {
20 |
21 | public static void main(String[] args) {
22 | launch(args);
23 | }
24 |
25 | public void start(Stage primaryStage) {
26 |
27 | Circle circle = new Circle(50, 150, 50, Color.RED);
28 |
29 | // change circle.translateXProperty from it's current value to 200
30 | KeyValue keyValue = new KeyValue(circle.translateXProperty(), 200);
31 |
32 | // over the course of 5 seconds
33 | KeyFrame keyFrame = new KeyFrame(Duration.seconds(10), keyValue);
34 | Timeline timeline = new Timeline(keyFrame);
35 |
36 | Scene scene = new Scene(new Pane(circle), 300, 250);
37 | primaryStage.setScene(scene);
38 | primaryStage.show();
39 |
40 | timeline.play();
41 | }
42 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/apps/AppExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.apps;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.layout.Pane;
7 | import javafx.stage.Stage;
8 |
9 | public class AppExample extends Application {
10 |
11 | public static void main(String[] args) {
12 | launch(args);
13 | }
14 |
15 | public void start(Stage primaryStage) {
16 |
17 | Label label = new Label("Minimal app");
18 |
19 | Scene scene = new Scene(new Pane(label), 300, 250);
20 | primaryStage.setScene(scene);
21 | primaryStage.show();
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/ButtonDefaultAndCancelModesExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.HBox;
7 | import javafx.stage.Stage;
8 |
9 | /**
10 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
11 | */
12 | public class ButtonDefaultAndCancelModesExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | @Override
19 | public void start(Stage primaryStage) {
20 |
21 | Button button = new Button("Click me!");
22 |
23 | button.setOnAction((event) -> {
24 | System.out.println("Button clicked!");
25 | });
26 |
27 | button.setCancelButton(false);
28 | button.setDefaultButton(false);
29 |
30 |
31 | Button buttonDefault = new Button("Default (OK)");
32 |
33 | buttonDefault.setOnAction((event) -> {
34 | System.out.println("Default Button clicked!");
35 | });
36 |
37 | buttonDefault.setCancelButton(false);
38 | buttonDefault.setDefaultButton(true);
39 |
40 |
41 | Button buttonCancel = new Button("Cancel");
42 |
43 | buttonCancel.setOnAction((event) -> {
44 | System.out.println("Cancel Button clicked!");
45 | });
46 |
47 | buttonCancel.setCancelButton(true);
48 | buttonCancel.setDefaultButton(false);
49 |
50 |
51 | HBox vbox = new HBox(button, buttonDefault, buttonCancel);
52 | Scene scene = new Scene(vbox);
53 | primaryStage.setScene(scene);
54 | primaryStage.setWidth(512);
55 | primaryStage.setHeight(512);
56 | primaryStage.show();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/ButtonExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | /**
10 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
11 | */
12 | public class ButtonExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | @Override
19 | public void start(Stage primaryStage) {
20 |
21 | Button button = new Button();
22 |
23 | button.setText("Click me!");
24 |
25 | button.setOnAction((event) -> {
26 | System.out.println("Button clicked!");
27 | });
28 |
29 |
30 | VBox vbox = new VBox(button);
31 | Scene scene = new Scene(vbox);
32 | primaryStage.setScene(scene);
33 | primaryStage.show();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/ButtonFXMLController.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.event.Event;
4 | import javafx.fxml.FXML;
5 | import javafx.scene.control.Button;
6 |
7 | public class ButtonFXMLController {
8 |
9 | public Button button1 = null;
10 | private int button1ClickCount = 0;
11 |
12 | @FXML
13 | public void buttonClicked(Event e){
14 | this.button1ClickCount++;
15 |
16 | String text = "Button1 clicked " + this.button1ClickCount + " times";
17 |
18 | System.out.println(text);
19 |
20 | button1.setText(text);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/ButtonFXMLExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Scene;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | import java.io.File;
10 | import java.net.URL;
11 |
12 | /**
13 | * Shows a simple JavaFX Button FXML example. The Button is declared in the assets/fxml/button-example.fxml file
14 | */
15 | public class ButtonFXMLExample extends Application {
16 |
17 | public static void main(String[] args) {
18 | launch(args);
19 | }
20 |
21 | @Override
22 | public void start(Stage primaryStage) throws Exception {
23 |
24 | FXMLLoader loader = new FXMLLoader();
25 |
26 | ButtonFXMLController controller = new ButtonFXMLController();
27 | loader.setController(controller);
28 |
29 | File fxmlFile = new File("assets/fxml/button-example.fxml");
30 | URL fxmlUrl = fxmlFile.toURI().toURL();
31 | loader.setLocation(fxmlUrl);
32 |
33 | VBox vbox = loader.load();
34 | Scene scene = new Scene(vbox);
35 |
36 | primaryStage.setScene(scene);
37 |
38 | primaryStage.setTitle("Button FXML Example");
39 | primaryStage.setWidth(300);
40 | primaryStage.setHeight(300);
41 | primaryStage.show();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/ButtonFontExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.text.Font;
8 | import javafx.scene.text.FontWeight;
9 | import javafx.stage.Stage;
10 |
11 | /**
12 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
13 | */
14 | public class ButtonFontExample extends Application {
15 |
16 | public static void main(String[] args) {
17 | launch(args);
18 | }
19 |
20 | @Override
21 | public void start(Stage primaryStage) {
22 | Button button = new Button("Click me!");
23 |
24 | Font font = Font.font("Courier New", FontWeight.BOLD, 36);
25 |
26 | button.setFont(font);
27 |
28 | button.setOnAction((event) -> {
29 | System.out.println("Button clicked!");
30 | });
31 |
32 |
33 | VBox vbox = new VBox(button);
34 | Scene scene = new Scene(vbox);
35 | primaryStage.setScene(scene);
36 | primaryStage.show();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/ButtonTransformationExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.transform.Scale;
8 | import javafx.stage.Stage;
9 |
10 | /**
11 | * Shows a Button that is disabled via the call to setDisable(true)
12 | */
13 | public class ButtonTransformationExample extends Application {
14 |
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | @Override
20 | public void start(Stage primaryStage) {
21 |
22 | Button button = new Button();
23 |
24 | button.setText("Click me!");
25 |
26 | button.setOnAction((event) -> {
27 | System.out.println("Button clicked!");
28 | });
29 |
30 | Scale scaleTransformation = new Scale();
31 | scaleTransformation.setX(3.0);
32 | scaleTransformation.setY(2.0);
33 | scaleTransformation.setPivotX(0);
34 | scaleTransformation.setPivotY(0);
35 |
36 | button.getTransforms().add(scaleTransformation);
37 |
38 | VBox vbox = new VBox(button);
39 | Scene scene = new Scene(vbox);
40 | primaryStage.setScene(scene);
41 | primaryStage.setWidth(512);
42 | primaryStage.setHeight(256);
43 | primaryStage.show();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/button/DisabledButtonExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.button;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | /**
10 | * Shows a Button that is disabled via the call to setDisable(true)
11 | */
12 | public class DisabledButtonExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | @Override
19 | public void start(Stage primaryStage) {
20 |
21 | Button button = new Button();
22 |
23 | button.setText("Click me!");
24 |
25 | button.setDisable(true);
26 |
27 | button.setOnAction((event) -> {
28 | System.out.println("Button clicked!");
29 | });
30 |
31 |
32 | VBox vbox = new VBox(button);
33 | Scene scene = new Scene(vbox);
34 | primaryStage.setScene(scene);
35 | primaryStage.show();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/canvas/CanvasExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.canvas;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.canvas.Canvas;
6 | import javafx.scene.canvas.GraphicsContext;
7 | import javafx.scene.layout.VBox;
8 | import javafx.scene.paint.Color;
9 | import javafx.stage.Stage;
10 |
11 | /**
12 | * Shows a simple JavaFX Canvas.
13 | */
14 | public class CanvasExample extends Application {
15 |
16 | public static void main(String[] args) {
17 | launch(args);
18 | }
19 |
20 | @Override
21 | public void start(Stage primaryStage) {
22 |
23 | Canvas canvas = new Canvas();
24 | canvas.setHeight(512);
25 | canvas.setWidth(512);
26 |
27 | GraphicsContext graphicsContext2D = canvas.getGraphicsContext2D();
28 |
29 | graphicsContext2D.setFill(Color.valueOf("#ff0000"));
30 | graphicsContext2D.fillRect(100, 100, 200, 200);
31 |
32 | graphicsContext2D.setStroke(Color.valueOf("#0000ff"));
33 | graphicsContext2D.strokeRect(200, 200, 200, 200);
34 |
35 | VBox vbox = new VBox(canvas);
36 | Scene scene = new Scene(vbox);
37 | primaryStage.setScene(scene);
38 | primaryStage.show();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/choicebox/ChoiceBoxExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.choicebox;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.ChoiceBox;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | /**
10 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
11 | */
12 | public class ChoiceBoxExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | @Override
19 | public void start(Stage primaryStage) {
20 |
21 | ChoiceBox choiceBox = new ChoiceBox();
22 |
23 | choiceBox.getItems().add("Choice 0");
24 | choiceBox.getItems().add("Choice 1");
25 | choiceBox.getItems().add("Choice 2");
26 |
27 | choiceBox.setOnAction((event) -> {
28 | int selectedIndex = choiceBox.getSelectionModel().getSelectedIndex();
29 | Object selectedItem = choiceBox.getSelectionModel().getSelectedItem();
30 |
31 | System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
32 | System.out.println(" ChoiceBox.getValue(): " + choiceBox.getValue());
33 | });
34 |
35 |
36 |
37 | VBox vbox = new VBox(choiceBox);
38 | Scene scene = new Scene(vbox);
39 | primaryStage.setScene(scene);
40 | primaryStage.setWidth(300);
41 | primaryStage.setHeight(300);
42 | primaryStage.setTitle("ChoiceBox Example");
43 | primaryStage.show();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/color/ColorExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.color;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.Background;
6 | import javafx.scene.layout.BackgroundFill;
7 | import javafx.scene.layout.Pane;
8 | import javafx.scene.layout.VBox;
9 | import javafx.scene.paint.Color;
10 | import javafx.stage.Stage;
11 |
12 | public class ColorExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | public void start(Stage primaryStage) {
19 |
20 | double red = 1.0;
21 | double green = 0.8;
22 | double blue = 0.6;
23 | double alpha = 1.0;
24 |
25 | Color color = new Color(red, green, blue, alpha);
26 | Color color1 = Color.web("#ff00ff");
27 | Color color1_1 = Color.web("hsl(270,100%,100%)");
28 | Color color2 = Color.web("#ff00ff", 0.5);
29 | Color color3 = Color.rgb(255, 0, 255);
30 | Color color4 = Color.rgb(255, 0, 255, 0.5);
31 | Color color5 = Color.grayRgb(255);
32 | Color color6 = Color.grayRgb(255, 0.5);
33 | Color color7 = Color.hsb(1.0, 0.5, 0.8);
34 | Color color8 = Color.hsb(1.0, 0.5, 0.8, 0.5);
35 | Color color9 = Color.color(1.0, 0.0, 1.0);
36 | Color color10 = Color.color(1.0, 0.0, 1.0, 0.5);
37 |
38 | Pane pane = new Pane();
39 | pane.setPrefWidth(300);
40 | pane.setPrefHeight(300);
41 |
42 | Background background = new Background(new BackgroundFill(color1_1, null, null));
43 | pane.setBackground(background);
44 |
45 | VBox vBox = new VBox(pane);
46 | Scene scene = new Scene(vBox);
47 |
48 | primaryStage.setScene(scene);
49 |
50 | primaryStage.show();
51 | }
52 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/colorpicker/ColorPickerExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.colorpicker;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.ColorPicker;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.paint.Color;
8 | import javafx.stage.Stage;
9 |
10 | public class ColorPickerExample extends Application {
11 | public static void main(String[] args) {
12 | launch(args);
13 | }
14 |
15 | @Override
16 | public void start(Stage primaryStage) {
17 | primaryStage.setTitle("JavaFX App");
18 |
19 | ColorPicker colorPicker = new ColorPicker();
20 |
21 | Color value = colorPicker.getValue();
22 |
23 | VBox vBox = new VBox(colorPicker);
24 | //HBox hBox = new HBox(button1, button2);
25 | Scene scene = new Scene(vBox, 960, 600);
26 |
27 | primaryStage.setScene(scene);
28 | primaryStage.show();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/combobox/ComboBoxExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.combobox;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.ChoiceBox;
6 | import javafx.scene.control.ComboBox;
7 | import javafx.scene.layout.VBox;
8 | import javafx.stage.Stage;
9 |
10 | /**
11 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
12 | */
13 | public class ComboBoxExample extends Application {
14 |
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | @Override
20 | public void start(Stage primaryStage) {
21 |
22 | ComboBox comboBox = new ComboBox();
23 |
24 | comboBox.getItems().add("Choice 0");
25 | comboBox.getItems().add("Choice 1");
26 | comboBox.getItems().add("Choice 2");
27 |
28 | comboBox.setEditable(true);
29 |
30 | comboBox.setOnAction((event) -> {
31 | int selectedIndex = comboBox.getSelectionModel().getSelectedIndex();
32 | Object selectedItem = comboBox.getSelectionModel().getSelectedItem();
33 |
34 | System.out.println("Selection made: [" + selectedIndex + "] " + selectedItem);
35 | System.out.println(" ChoiceBox.getValue(): " + comboBox.getValue());
36 | });
37 |
38 | VBox vbox = new VBox(comboBox);
39 | Scene scene = new Scene(vbox);
40 | primaryStage.setScene(scene);
41 | primaryStage.setWidth(300);
42 | primaryStage.setHeight(300);
43 | primaryStage.setTitle("ComboBox Example");
44 | primaryStage.show();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/concurrency/ConcurrencyExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.concurrency;
2 |
3 | import javafx.application.Application;
4 | import javafx.application.Platform;
5 | import javafx.scene.Scene;
6 | import javafx.scene.control.ProgressBar;
7 | import javafx.scene.layout.VBox;
8 | import javafx.stage.Stage;
9 |
10 | public class ConcurrencyExample extends Application {
11 | public static void main(String[] args) {
12 | launch(args);
13 | }
14 |
15 | @Override
16 | public void start(Stage primaryStage) {
17 | primaryStage.setTitle("JavaFX App");
18 |
19 | ProgressBar progressBar = new ProgressBar(0);
20 |
21 | VBox vBox = new VBox(progressBar);
22 | Scene scene = new Scene(vBox, 960, 600);
23 |
24 | primaryStage.setScene(scene);
25 | primaryStage.show();
26 |
27 |
28 | Thread taskThread = new Thread(new Runnable() {
29 | @Override
30 | public void run() {
31 | double progress = 0;
32 | for(int i=0; i<10; i++){
33 | try {
34 | Thread.sleep(1000);
35 | } catch (InterruptedException e) {
36 | e.printStackTrace();
37 | }
38 | progress += 0.1;
39 |
40 | double reportedProgress = progress;
41 | Platform.runLater(new Runnable() {
42 | @Override
43 | public void run() {
44 | progressBar.setProgress(reportedProgress);
45 | }
46 | });
47 | }
48 |
49 | }
50 | });
51 |
52 | taskThread.start();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/contextmenu/ContextMenuExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.contextmenu;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.ContextMenu;
6 | import javafx.scene.control.MenuItem;
7 | import javafx.scene.control.TextArea;
8 | import javafx.scene.layout.VBox;
9 | import javafx.stage.Stage;
10 |
11 | public class ContextMenuExample extends Application {
12 |
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | public void start(Stage primaryStage) {
18 |
19 | ContextMenu contextMenu = new ContextMenu();
20 | MenuItem menuItem1 = new MenuItem("Choice 1");
21 | MenuItem menuItem2 = new MenuItem("Choice 2");
22 | MenuItem menuItem3 = new MenuItem("Choice 3");
23 |
24 | menuItem3.setOnAction((event) -> {
25 | System.out.println("Choice 3 clicked!");
26 | });
27 |
28 | contextMenu.getItems().addAll(menuItem1,menuItem2,menuItem3);
29 |
30 | TextArea textArea = new TextArea();
31 |
32 | textArea.setContextMenu(contextMenu);
33 |
34 | VBox vBox = new VBox(textArea);
35 | Scene scene = new Scene(vBox);
36 |
37 | primaryStage.setScene(scene);
38 | primaryStage.setTitle("JavaFX App");
39 |
40 | primaryStage.show();
41 | }
42 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/directorychooser/DirectoryChooserExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.directorychooser;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.DirectoryChooser;
8 | import javafx.stage.Stage;
9 |
10 | import java.io.File;
11 |
12 | public class DirectoryChooserExample extends Application {
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | @Override
18 | public void start(Stage primaryStage) {
19 | primaryStage.setTitle("JavaFX App");
20 |
21 | DirectoryChooser directoryChooser = new DirectoryChooser();
22 | directoryChooser.setInitialDirectory(new File("src"));
23 |
24 | Button button = new Button("Select Directory");
25 | button.setOnAction(e -> {
26 | File selectedDirectory = directoryChooser.showDialog(primaryStage);
27 |
28 | System.out.println(selectedDirectory.getAbsolutePath());
29 | });
30 |
31 |
32 | VBox vBox = new VBox(button);
33 | //HBox hBox = new HBox(button1, button2);
34 | Scene scene = new Scene(vBox, 960, 600);
35 |
36 | primaryStage.setScene(scene);
37 | primaryStage.show();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/draganddrop/DragAndDropExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.draganddrop;
2 |
3 | import javafx.application.Application;
4 | import javafx.event.EventHandler;
5 | import javafx.scene.Scene;
6 | import javafx.scene.input.*;
7 | import javafx.scene.layout.Pane;
8 | import javafx.scene.paint.Color;
9 | import javafx.scene.shape.Circle;
10 | import javafx.stage.Stage;
11 |
12 | public class DragAndDropExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | public void start(Stage primaryStage) {
19 |
20 | Circle circle = createCircle("#ff00ff", "#ff88ff",100);
21 |
22 | circle.setOnDragDetected((MouseEvent event) -> {
23 | System.out.println("Circle 1 drag detected");
24 |
25 | Dragboard db = circle.startDragAndDrop(TransferMode.ANY);
26 |
27 | // set drag and drop data
28 | ClipboardContent content = new ClipboardContent();
29 | content.putString("Circle source text");
30 | db.setContent(content);
31 | });
32 | circle.setOnMouseDragged((MouseEvent event) -> {
33 | //System.out.println("Circle 1 mouse dragged");
34 | event.setDragDetect(true);
35 | });
36 |
37 | Circle circle2 = createCircle("#00ffff", "#88ffff",300);
38 |
39 | circle2.setOnDragOver(new EventHandler() {
40 | public void handle(DragEvent event) {
41 | if (event.getGestureSource() != circle2 && event.getDragboard().hasString()) {
42 | event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
43 | }
44 |
45 | event.consume();
46 | }
47 | });
48 |
49 | circle2.setOnDragDropped((DragEvent event) -> {
50 | Dragboard db = event.getDragboard();
51 | if (db.hasString()) {
52 | System.out.println("Dropped: " + db.getString());
53 | event.setDropCompleted(true);
54 | } else {
55 | event.setDropCompleted(false);
56 | }
57 | //event.setDropCompleted(true);
58 | event.consume();
59 | });
60 |
61 |
62 |
63 |
64 | Pane pane = new Pane();
65 | pane.getChildren().add(circle);
66 | pane.getChildren().add(circle2);
67 |
68 | Scene scene = new Scene(pane, 1024, 800, true);
69 | primaryStage.setScene(scene);
70 | primaryStage.setTitle("2D Example");
71 |
72 | primaryStage.show();
73 | }
74 |
75 | private Circle createCircle(String strokeColor, String fillColor, double x) {
76 | Circle circle = new Circle();
77 | circle.setCenterX(x);
78 | circle.setCenterY(200);
79 | circle.setRadius(50);
80 | circle.setStroke(Color.valueOf(strokeColor));
81 | circle.setStrokeWidth(5);
82 | circle.setFill(Color.valueOf(fillColor));
83 | return circle;
84 | }
85 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/draganddrop/DragAndDropExampleDraft.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.draganddrop;
2 |
3 | import javafx.application.Application;
4 | import javafx.event.EventHandler;
5 | import javafx.scene.Scene;
6 | import javafx.scene.input.*;
7 | import javafx.scene.layout.Pane;
8 | import javafx.scene.paint.Color;
9 | import javafx.scene.shape.Circle;
10 | import javafx.stage.Stage;
11 |
12 | public class DragAndDropExampleDraft extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | public void start(Stage primaryStage) {
19 |
20 | Circle circle = createCircle("#ff00ff", "#ff88ff",100);
21 |
22 | circle.setOnDragDetected((MouseEvent event) -> {
23 | System.out.println("Circle 1 drag detected");
24 |
25 | Dragboard db = circle.startDragAndDrop(TransferMode.ANY);
26 |
27 | // set drag and drop data
28 | ClipboardContent content = new ClipboardContent();
29 | content.putString("Circle source text");
30 | db.setContent(content);
31 | });
32 | circle.setOnDragDone((DragEvent event) -> {
33 | System.out.println("Circle 1 Drag and Drop Done");
34 | event.consume();
35 | });
36 | circle.setOnDragDropped((DragEvent event) -> {
37 | System.out.println("Circle 1 drag dropped");
38 | });
39 |
40 | circle.setOnMouseDragged((MouseEvent event) -> {
41 | //System.out.println("Circle 1 mouse dragged");
42 | event.setDragDetect(true);
43 | });
44 | circle.setOnMousePressed((MouseEvent event) -> {
45 | //circle.setMouseTransparent(true);
46 | });
47 | circle.setOnMouseReleased((MouseEvent event) -> {
48 | //circle.setMouseTransparent(false);
49 | });
50 |
51 | Circle circle2 = createCircle("#00ffff", "#88ffff",300);
52 |
53 | circle2.setOnMouseDragEntered((MouseEvent event) -> {
54 | circle2.setStroke(Color.valueOf("#ff8888"));
55 | });
56 | circle2.setOnMouseDragExited((MouseEvent event) -> {
57 | circle2.setStroke(Color.valueOf("#00ffff"));
58 | });
59 |
60 | circle2.setOnMouseDragReleased((MouseEvent event) -> {
61 | //System.out.println("Circle 2 -> Drag and dropped...");
62 | });
63 |
64 | circle2.setOnDragOver(new EventHandler() {
65 | public void handle(DragEvent event) {
66 | if (event.getGestureSource() != circle2 && event.getDragboard().hasString()) {
67 | event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
68 | }
69 |
70 | event.consume();
71 | }
72 | });
73 |
74 | circle2.setOnDragDropped((DragEvent event) -> {
75 | Dragboard db = event.getDragboard();
76 | if (db.hasString()) {
77 | System.out.println("Dropped: " + db.getString());
78 | event.setDropCompleted(true);
79 | } else {
80 | event.setDropCompleted(false);
81 | }
82 | //event.setDropCompleted(true);
83 | event.consume();
84 | });
85 |
86 |
87 |
88 |
89 | Pane pane = new Pane();
90 | pane.getChildren().add(circle);
91 | pane.getChildren().add(circle2);
92 |
93 | Scene scene = new Scene(pane, 1024, 800, true);
94 | primaryStage.setScene(scene);
95 | primaryStage.setTitle("2D Example");
96 |
97 | primaryStage.show();
98 | }
99 |
100 | private Circle createCircle(String strokeColor, String fillColor, double x) {
101 | Circle circle = new Circle();
102 | circle.setCenterX(x);
103 | circle.setCenterY(200);
104 | circle.setRadius(50);
105 | circle.setStroke(Color.valueOf(strokeColor));
106 | circle.setStrokeWidth(5);
107 | circle.setFill(Color.valueOf(fillColor));
108 | return circle;
109 | }
110 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/filechooser/FileChooserExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.filechooser;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.FileChooser;
8 | import javafx.stage.Stage;
9 |
10 | import java.io.File;
11 |
12 | public class FileChooserExample extends Application {
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | @Override
18 | public void start(Stage primaryStage) {
19 | primaryStage.setTitle("JavaFX App");
20 |
21 | FileChooser fileChooser = new FileChooser();
22 | fileChooser.setInitialDirectory(new File("src"));
23 | fileChooser.setInitialFileName("myfile.txt");
24 | /*
25 | fileChooser.getExtensionFilters().addAll(
26 | new FileChooser.ExtensionFilter("Text Files", "*.txt")
27 | ,new FileChooser.ExtensionFilter("HTML Files", "*.htm")
28 | );
29 | */
30 |
31 | Button button = new Button("Select File");
32 | button.setOnAction(e -> {
33 | File selectedFile = fileChooser.showOpenDialog(primaryStage);
34 |
35 | System.out.println(selectedFile.getAbsolutePath());
36 | });
37 |
38 |
39 | VBox vBox = new VBox(button);
40 | //HBox hBox = new HBox(button1, button2);
41 | Scene scene = new Scene(vBox, 960, 600);
42 |
43 | primaryStage.setScene(scene);
44 | primaryStage.show();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/font/FontExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.font;
2 |
3 | import javafx.application.Application;
4 | import javafx.geometry.VPos;
5 | import javafx.scene.Scene;
6 | import javafx.scene.layout.Pane;
7 | import javafx.scene.paint.Color;
8 | import javafx.scene.text.*;
9 | import javafx.stage.Stage;
10 |
11 | import java.util.List;
12 |
13 | public class FontExample extends Application {
14 |
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | public void start(Stage primaryStage) {
20 |
21 | //Font creation examples. The Font instances are not used. Examples illustrate instantiation only.
22 | String fontFamily = "Arial";
23 | double fontSize = 13;
24 | FontWeight fontWeight = FontWeight.BOLD;
25 | FontPosture fontPosture = FontPosture.ITALIC;
26 |
27 | Font font1 = Font.font(fontFamily);
28 | Font font2 = Font.font(fontSize);
29 | Font font3 = Font.font(fontFamily, fontSize);
30 | Font font4 = Font.font(fontFamily, fontWeight , fontSize);
31 | Font font5 = Font.font(fontFamily, fontPosture, fontSize);
32 | Font font6 = Font.font(fontFamily, fontWeight , fontPosture, fontSize);
33 |
34 |
35 | //Font instances in use - examples
36 | Font arialFont = Font.font("Arial");
37 | Font arialFontBold36 = Font.font("Arial", FontWeight.BOLD, 36);
38 |
39 | Text textArial = createText("Text in Arial", arialFont, 0, 30);
40 | Text textArialBold36 = createText("Text in Arial Bold 36", arialFontBold36, 0, 70);
41 |
42 | Font robotoFont = Font.font("Roboto");
43 | Font robotoFontBold36 = Font.font("Roboto", FontWeight.BOLD, 36);
44 |
45 | Text textRoboto = createText("Text in Roboto", robotoFont, 0, 100);
46 | Text textRobotoBold36 = createText("Text in Roboto Bold 36", robotoFontBold36, 0, 140);
47 |
48 | Font courierNewFont = Font.font("Courier New");
49 | Font courierNewFontBold36 = Font.font("Courier New", FontWeight.BOLD, 36);
50 |
51 | Text textCourierNew = createText("Text in Courier New", courierNewFont, 0, 180);
52 | Text textCourierNewBold36 = createText("Text in Courier New Bold 36", courierNewFontBold36, 0, 220);
53 |
54 |
55 | Pane pane = new Pane();
56 | pane.getChildren().add(textArial);
57 | pane.getChildren().add(textArialBold36);
58 | pane.getChildren().add(textRoboto);
59 | pane.getChildren().add(textRobotoBold36);
60 | pane.getChildren().add(textCourierNew);
61 | pane.getChildren().add(textCourierNewBold36);
62 |
63 | Scene scene = new Scene(pane, 600, 250);
64 | primaryStage.setScene(scene);
65 | primaryStage.show();
66 |
67 | List fontFamilies = Font.getFamilies();
68 | List fontNames = Font.getFontNames();
69 |
70 | System.out.println("=====================");
71 | System.out.println("Font families: " + fontFamilies.size());
72 | System.out.println("=====================");
73 | printList(fontFamilies);
74 | System.out.println("=====================");
75 | System.out.println("Font names: " + fontNames.size());
76 | System.out.println("=====================");
77 | printList(fontNames);
78 |
79 | }
80 |
81 | private void printList(List list) {
82 | for(String item : list) {
83 | System.out.println(item);
84 | }
85 | }
86 |
87 | private Text createText(String textToDisplay, Font font, double x, double y) {
88 | Text text = new Text(textToDisplay);
89 | text.setFontSmoothingType(FontSmoothingType.GRAY);
90 | text.setFont(font);
91 | text.setFill(Color.DARKMAGENTA);
92 | text.setTextOrigin(VPos.BASELINE);
93 |
94 | text.setX(x);
95 | text.setY(y);
96 |
97 | return text;
98 | }
99 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/fxml/FXMLExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.fxml;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Scene;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.media.Media;
8 | import javafx.stage.Stage;
9 |
10 | import java.io.File;
11 | import java.net.URL;
12 |
13 | public class FXMLExample extends Application{
14 |
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | @Override
20 | public void start(Stage primaryStage) throws Exception {
21 | FXMLLoader loader = new FXMLLoader();
22 |
23 | MyFxmlController controller = new MyFxmlController();
24 | controller.setValue("New value");
25 | loader.setController(controller);
26 |
27 | File fxmlFile = new File("assets/fxml/hello-world.fxml");
28 | URL fxmlUrl = fxmlFile.toURI().toURL();
29 | loader.setLocation(fxmlUrl);
30 |
31 | VBox vbox = loader.load();
32 |
33 | MyFxmlController controllerRef = loader.getController();
34 | System.out.println(controllerRef.getValue());
35 | System.out.println(controllerRef.getLabel1Text());
36 | System.out.println(controllerRef.getLabel2Text());
37 |
38 | Scene scene = new Scene(vbox);
39 | primaryStage.setScene(scene);
40 | primaryStage.show();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/fxml/MyFxmlController.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.fxml;
2 |
3 | import javafx.event.Event;
4 | import javafx.fxml.FXML;
5 | import javafx.scene.control.Label;
6 |
7 | public class MyFxmlController {
8 |
9 | private String value = "Default value";
10 |
11 | public Label label1 = null;
12 | public Label label2 = null;
13 |
14 |
15 |
16 | public String getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(String value) {
21 | this.value = value;
22 | }
23 |
24 | public void initialize() {
25 | System.out.println("Initialized MyFxmlController");
26 | }
27 |
28 | public String getLabel1Text() {
29 | return this.label1.getText();
30 | }
31 |
32 | public String getLabel2Text() {
33 | return this.label2.getText();
34 | }
35 |
36 | @FXML
37 | public void buttonClicked(Event e){
38 | System.out.println("Button clicked");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/gfx2d/Gfx2DExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.gfx2d;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.Pane;
6 | import javafx.scene.paint.Color;
7 | import javafx.scene.shape.Circle;
8 | import javafx.scene.shape.Rectangle;
9 | import javafx.stage.Stage;
10 |
11 | public class Gfx2DExample extends Application {
12 |
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | public void start(Stage primaryStage) {
18 |
19 | Circle circle = new Circle();
20 | circle.setCenterX(100);
21 | circle.setCenterY(100);
22 | circle.setRadius(125);
23 | circle.setStroke(Color.valueOf("#ff00ff"));
24 | circle.setStrokeWidth(5);
25 | circle.setFill(Color.TRANSPARENT);
26 |
27 | Rectangle rectangle = new Rectangle();
28 | rectangle.setX(200);
29 | rectangle.setY(200);
30 | rectangle.setWidth(300);
31 | rectangle.setHeight(400);
32 | rectangle.setStroke(Color.TRANSPARENT);
33 | rectangle.setFill(Color.valueOf("#00ffff"));
34 |
35 | Pane pane = new Pane();
36 | pane.getChildren().add(circle);
37 | pane.getChildren().add(rectangle);
38 |
39 | Scene scene = new Scene(pane, 1024, 800, true);
40 | primaryStage.setScene(scene);
41 | primaryStage.setTitle("2D Example");
42 |
43 | primaryStage.show();
44 | }
45 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/gfx3d/Gfx3DExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.gfx3d;
2 |
3 | import javafx.application.Application;
4 | import javafx.application.ConditionalFeature;
5 | import javafx.application.Platform;
6 | import javafx.scene.Group;
7 | import javafx.scene.PerspectiveCamera;
8 | import javafx.scene.Scene;
9 | import javafx.scene.shape.Box;
10 | import javafx.scene.shape.CullFace;
11 | import javafx.scene.transform.Rotate;
12 | import javafx.stage.Stage;
13 |
14 | public class Gfx3DExample extends Application {
15 |
16 | public static void main(String[] args) {
17 | launch(args);
18 | }
19 |
20 | public void start(Stage primaryStage) {
21 |
22 | boolean is3DSupported = Platform.isSupported(ConditionalFeature.SCENE3D);
23 | if(!is3DSupported) {
24 | System.out.println("Sorry, 3D is not supported in JavaFX on this platform.");
25 | return;
26 | }
27 |
28 | Box box = new Box(100,100,100);
29 | box.setCullFace(CullFace.NONE);
30 | box.setTranslateX(250);
31 | box.setTranslateY(100);
32 | box.setTranslateZ(400);
33 |
34 | boolean fixedEyeAtCameraZero = false;
35 | PerspectiveCamera camera = new PerspectiveCamera(fixedEyeAtCameraZero);
36 | camera.setTranslateX(150);
37 | camera.setTranslateY(-100);
38 | camera.setTranslateZ(250);
39 |
40 | Group root = new Group(box);
41 | root.setRotationAxis(Rotate.X_AXIS);
42 | root.setRotate(30);
43 |
44 | Scene scene = new Scene(root, 500, 300, true);
45 | scene.setCamera(camera);
46 | primaryStage.setScene(scene);
47 | primaryStage.setTitle("3D Example");
48 |
49 | primaryStage.show();
50 | }
51 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/gfx3d/Gfx3DExampleDraft.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.gfx3d;
2 |
3 | import javafx.animation.Animation;
4 | import javafx.animation.RotateTransition;
5 | import javafx.application.Application;
6 | import javafx.application.ConditionalFeature;
7 | import javafx.application.Platform;
8 | import javafx.scene.Group;
9 | import javafx.scene.PerspectiveCamera;
10 | import javafx.scene.PointLight;
11 | import javafx.scene.Scene;
12 | import javafx.scene.paint.Color;
13 | import javafx.scene.shape.Box;
14 | import javafx.scene.shape.CullFace;
15 | import javafx.scene.transform.Rotate;
16 | import javafx.stage.Stage;
17 | import javafx.util.Duration;
18 |
19 | public class Gfx3DExampleDraft extends Application {
20 |
21 | public static void main(String[] args) {
22 | launch(args);
23 | }
24 |
25 | public void start(Stage primaryStage) {
26 |
27 | boolean is3DSupported = Platform.isSupported(ConditionalFeature.SCENE3D);
28 | if(!is3DSupported) {
29 | System.out.println("Sorry, 3D is not supported in JavaFX on this platform.");
30 | return;
31 | }
32 |
33 | Box box = new Box(100,100,100);
34 | box.setCullFace(CullFace.NONE);
35 | box.setTranslateX(450);
36 | box.setTranslateY(100);
37 | box.setTranslateZ(400);
38 |
39 | boolean fixedEyeAtCameraZero = false;
40 | PerspectiveCamera camera = new PerspectiveCamera(fixedEyeAtCameraZero);
41 | camera.setTranslateX(100);
42 | camera.setTranslateY(-75);
43 | camera.setTranslateZ(300);
44 |
45 | RotateTransition rotateTransition = new RotateTransition(Duration.seconds(2), camera);
46 | rotateTransition.setCycleCount(Animation.INDEFINITE);
47 | rotateTransition.setFromAngle(0);
48 | rotateTransition.setToAngle(360);
49 | rotateTransition.setAutoReverse(true);
50 | rotateTransition.setAxis(Rotate.X_AXIS);
51 | rotateTransition.play();
52 |
53 | PointLight redLight = new PointLight();
54 | redLight.setColor(Color.valueOf("#ff0000"));
55 | redLight.setTranslateX(250);
56 | redLight.setTranslateY(-100);
57 | redLight.setTranslateZ(250);
58 |
59 | PointLight greenLight = new PointLight();
60 | greenLight.setColor(Color.valueOf("#00ff00"));
61 | greenLight.setTranslateX(275);
62 | greenLight.setTranslateY(325);
63 | greenLight.setTranslateZ(325);
64 |
65 | Group root = new Group(box, redLight, greenLight);
66 | root.setRotationAxis(Rotate.X_AXIS);
67 | root.setRotate(70);
68 |
69 | Scene scene = new Scene(root, 500, 300, true); //true = use depth buffer in Scene
70 | scene.setCamera(camera);
71 | primaryStage.setScene(scene);
72 | primaryStage.setTitle("3D Example");
73 |
74 | primaryStage.show();
75 | }
76 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/gfx3d/Gfx3DExperiments.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.gfx3d;
2 |
3 | import javafx.application.Application;
4 | import javafx.application.ConditionalFeature;
5 | import javafx.application.Platform;
6 | import javafx.scene.DepthTest;
7 | import javafx.scene.Group;
8 | import javafx.scene.PerspectiveCamera;
9 | import javafx.scene.Scene;
10 | import javafx.scene.paint.Color;
11 | import javafx.scene.paint.PhongMaterial;
12 | import javafx.scene.shape.Box;
13 | import javafx.scene.shape.CullFace;
14 | import javafx.scene.transform.Rotate;
15 | import javafx.stage.Stage;
16 |
17 | public class Gfx3DExperiments extends Application {
18 |
19 | public static void main(String[] args) {
20 | launch(args);
21 | }
22 |
23 | public void start(Stage primaryStage) throws InterruptedException {
24 |
25 | boolean is3DSupported = Platform.isSupported(ConditionalFeature.SCENE3D);
26 | if(!is3DSupported) {
27 | System.out.println("Sorry, 3D is not supported in JavaFX on this platform.");
28 | return;
29 | }
30 |
31 | Box box1 = Gfx3DUtil.createBox(100, 100, 100, 250, 100, 200);
32 | Box box2 = Gfx3DUtil.createBox(100, 100, 100, 300, 150, 400);
33 |
34 | PhongMaterial material = new PhongMaterial();
35 | material.setDiffuseColor(Color.TEAL);
36 | box2.setMaterial(material);
37 |
38 | PerspectiveCamera camera = Gfx3DUtil.createPerspectiveCamera(false, 150, -100, 250);
39 |
40 | Group root = new Group(box1, box2);
41 | //root.setRotationAxis(Rotate.X_AXIS);
42 | //root.setRotate(30);
43 |
44 | Scene scene = new Scene(root, 500, 300, true);
45 | scene.setCamera(camera);
46 | primaryStage.setScene(scene);
47 | primaryStage.setTitle("3D Example");
48 |
49 | primaryStage.setX(200);
50 |
51 | primaryStage.show();
52 |
53 | Thread thread = new Thread(() -> {
54 | try {
55 | Thread.sleep(1000);
56 | Platform.runLater(() -> {
57 | camera.setRotationAxis(Rotate.X_AXIS);
58 | camera.setRotate(10);
59 | });
60 | Thread.sleep(1000);
61 | Platform.runLater(() -> {
62 | camera.setRotationAxis(Rotate.X_AXIS);
63 | camera.setRotate(20);
64 | });
65 | Thread.sleep(1000);
66 | Platform.runLater(() -> {
67 | camera.setRotationAxis(Rotate.X_AXIS);
68 | camera.setRotate(30);
69 | });
70 | } catch (InterruptedException e) {
71 | System.out.println("Thread interrupted: " + e.getMessage());
72 | }
73 |
74 | });
75 | thread.start();
76 |
77 | /*
78 | Thread.sleep(1000);
79 | Platform.runLater(() -> { camera.setRotationAxis(Rotate.X_AXIS); camera.setRotate(10);});
80 | Thread.sleep(1000);
81 | Platform.runLater(() -> { camera.setRotationAxis(Rotate.X_AXIS); camera.setRotate(20);});
82 | Thread.sleep(1000);
83 | Platform.runLater(() -> { camera.setRotationAxis(Rotate.X_AXIS); camera.setRotate(30);});
84 | */
85 | }
86 |
87 |
88 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/gfx3d/Gfx3DUtil.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.gfx3d;
2 |
3 | import javafx.scene.PerspectiveCamera;
4 | import javafx.scene.shape.Box;
5 | import javafx.scene.shape.CullFace;
6 |
7 | public class Gfx3DUtil {
8 |
9 | public static PerspectiveCamera createPerspectiveCamera(
10 | boolean fixedEyeAtCameraZero, double x, double y, double z ) {
11 | PerspectiveCamera camera = new PerspectiveCamera(fixedEyeAtCameraZero);
12 | camera.setTranslateX(x);
13 | camera.setTranslateY(y);
14 | camera.setTranslateZ(z);
15 | return camera;
16 | }
17 |
18 | public static Box createBox(double width, double height, double depth, double x, double y, double z) {
19 | Box box = new Box(width, height, depth);
20 | box.setCullFace(CullFace.NONE);
21 | box.setTranslateX(x);
22 | box.setTranslateY(y);
23 | box.setTranslateZ(z);
24 |
25 | return box;
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/htmleditor/HtmlEditorExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.htmleditor;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.VBox;
6 | import javafx.scene.web.HTMLEditor;
7 | import javafx.stage.Stage;
8 |
9 | public class HtmlEditorExample extends Application {
10 |
11 | public static void main(String[] args) {
12 | launch(args);
13 | }
14 |
15 | public void start(Stage primaryStage) {
16 |
17 | HTMLEditor htmlEditor = new HTMLEditor();
18 |
19 | String htmlText = "Bold text";
20 | htmlEditor.setHtmlText(htmlText);
21 |
22 | String htmlTextEdited = htmlEditor.getHtmlText();
23 | System.out.println(htmlTextEdited);
24 |
25 |
26 |
27 |
28 | VBox vBox = new VBox(htmlEditor);
29 | Scene scene = new Scene(vBox);
30 |
31 | primaryStage.setScene(scene);
32 | primaryStage.setTitle("JavaFX App");
33 |
34 | primaryStage.show();
35 | }
36 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/hyperlink/HyperlinkChangeTextExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.hyperlink;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Hyperlink;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | public class HyperlinkChangeTextExample extends Application {
10 | public static void main(String[] args) {
11 | launch(args);
12 | }
13 |
14 | @Override
15 | public void start(Stage primaryStage) {
16 | primaryStage.setTitle("JavaFX App");
17 |
18 | Hyperlink link = new Hyperlink("Click Me!");
19 |
20 | link.setText("New Link Text");
21 |
22 | link.setOnAction((event) -> {
23 | System.out.println("Hyperlink clicked");
24 | });
25 |
26 | VBox vBox = new VBox(link);
27 | Scene scene = new Scene(vBox, 300, 300);
28 |
29 | primaryStage.setScene(scene);
30 | primaryStage.show();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/hyperlink/HyperlinkExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.hyperlink;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Hyperlink;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | public class HyperlinkExample extends Application {
10 | public static void main(String[] args) {
11 | launch(args);
12 | }
13 |
14 | @Override
15 | public void start(Stage primaryStage) {
16 | primaryStage.setTitle("JavaFX App");
17 |
18 | Hyperlink link = new Hyperlink("Click Me!");
19 |
20 | link.setOnAction((event) -> {
21 | System.out.println("Hyperlink clicked");
22 | });
23 |
24 | VBox vBox = new VBox(link);
25 | Scene scene = new Scene(vBox, 300, 300);
26 |
27 | primaryStage.setScene(scene);
28 | primaryStage.show();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/hyperlink/HyperlinkFontExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.hyperlink;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Hyperlink;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.text.Font;
8 | import javafx.scene.text.FontWeight;
9 | import javafx.stage.Stage;
10 |
11 | public class HyperlinkFontExample extends Application {
12 | public static void main(String[] args) {
13 | launch(args);
14 | }
15 |
16 | @Override
17 | public void start(Stage primaryStage) {
18 | primaryStage.setTitle("JavaFX App");
19 |
20 | Hyperlink link = new Hyperlink("Click Me!");
21 |
22 | Font courierNewFontBold36 = Font.font("Courier New", FontWeight.BOLD, 36);
23 |
24 | link.setFont(courierNewFontBold36);
25 |
26 | link.setOnAction((event) -> {
27 | System.out.println("Hyperlink clicked");
28 | });
29 |
30 | VBox vBox = new VBox(link);
31 | Scene scene = new Scene(vBox, 200, 200);
32 |
33 | primaryStage.setScene(scene);
34 | primaryStage.show();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/imageview/ImageViewExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.imageview;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Accordion;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.TitledPane;
8 | import javafx.scene.image.Image;
9 | import javafx.scene.image.ImageView;
10 | import javafx.scene.layout.VBox;
11 | import javafx.stage.Stage;
12 |
13 | import java.io.FileInputStream;
14 | import java.io.FileNotFoundException;
15 |
16 | public class ImageViewExample extends Application {
17 |
18 | public static void main(String[] args) {
19 | launch(args);
20 | }
21 |
22 | public void start(Stage primaryStage) {
23 |
24 | FileInputStream input = null;
25 | try {
26 | input = new FileInputStream("assets/media/abstract-5719221_640.jpg");
27 | } catch (FileNotFoundException e) {
28 | e.printStackTrace();
29 | }
30 | Image image = new Image(input);
31 | ImageView imageView = new ImageView(image);
32 |
33 |
34 | VBox vBox = new VBox(imageView);
35 | Scene scene = new Scene(vBox);
36 |
37 | primaryStage.setScene(scene);
38 |
39 | primaryStage.show();
40 | }
41 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/label/LabelChangeTextExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.label;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | public class LabelChangeTextExample extends Application {
10 |
11 | public static void main(String[] args) {
12 | launch(args);
13 | }
14 |
15 | public void start(Stage primaryStage) {
16 |
17 | Label label = new Label("Initial Label Text");
18 |
19 | label.setText("New Label Text");
20 |
21 | VBox vBox = new VBox(label);
22 | Scene scene = new Scene(vBox);
23 |
24 | primaryStage.setScene(scene);
25 | primaryStage.setTitle("JavaFX App");
26 |
27 | primaryStage.show();
28 | }
29 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/label/LabelExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.label;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.text.Font;
8 | import javafx.stage.Stage;
9 |
10 | public class LabelExample extends Application {
11 |
12 | public static void main(String[] args) {
13 | launch(args);
14 | }
15 |
16 | public void start(Stage primaryStage) {
17 |
18 | Label label = new Label("Label Text");
19 |
20 | VBox vBox = new VBox(label);
21 | Scene scene = new Scene(vBox);
22 |
23 | primaryStage.setScene(scene);
24 | primaryStage.setTitle("JavaFX App");
25 |
26 | primaryStage.show();
27 | }
28 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/label/LabelFontExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.label;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.layout.VBox;
7 | import javafx.scene.text.Font;
8 | import javafx.stage.Stage;
9 |
10 | public class LabelFontExample extends Application {
11 |
12 | public static void main(String[] args) {
13 | launch(args);
14 | }
15 |
16 | public void start(Stage primaryStage) {
17 |
18 | Label label = new Label("A label with custom font set.");
19 |
20 | label.setFont(new Font("Arial", 24));
21 |
22 | VBox vBox = new VBox(label);
23 | Scene scene = new Scene(vBox);
24 |
25 | primaryStage.setScene(scene);
26 | primaryStage.setTitle("JavaFX App");
27 |
28 | primaryStage.show();
29 | }
30 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/layout/AutoResponsiveLayoutExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.layout;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.*;
6 | import javafx.scene.layout.*;
7 | import javafx.scene.paint.Color;
8 | import javafx.scene.shape.StrokeLineCap;
9 | import javafx.scene.shape.StrokeLineJoin;
10 | import javafx.scene.shape.StrokeType;
11 | import javafx.scene.text.Font;
12 | import javafx.scene.text.FontPosture;
13 | import javafx.scene.text.FontWeight;
14 | import javafx.stage.Stage;
15 |
16 | import java.util.List;
17 |
18 | public class AutoResponsiveLayoutExample extends Application {
19 |
20 | private int widgetCount = 0;
21 |
22 | public static void main(String[] args) {
23 | launch(args);
24 | }
25 |
26 | public void start(Stage primaryStage) {
27 | ScrollPane scrollPane = new ScrollPane();
28 |
29 | scrollPane.pannableProperty().set(true);
30 | scrollPane.fitToWidthProperty().set(true);
31 | //scrollPane.fitToHeightProperty().set(true);
32 |
33 | //scrollPane.setPrefHeight(1024);
34 | scrollPane.setPrefHeight(4096);
35 |
36 | scrollPane.hbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.AS_NEEDED);
37 | scrollPane.vbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.AS_NEEDED);
38 |
39 | Pane containerPane = new Pane();
40 | scrollPane.setContent(containerPane);
41 | AutoResponsiveLayout autoResponsiveLayout = new AutoResponsiveLayout(containerPane, scrollPane);
42 |
43 | ToolBar toolbar = createToolBar(containerPane, autoResponsiveLayout);
44 |
45 | //VBox vBox = new VBox(toolbar, containerPane);
46 | VBox vBox = new VBox(toolbar, scrollPane);
47 | Scene scene = new Scene(vBox);
48 | primaryStage.setScene(scene);
49 |
50 | primaryStage.setWidth(1024);
51 | primaryStage.setHeight(800);
52 | primaryStage.setTitle("Auto-responsive Layout Example");
53 |
54 | primaryStage.show();
55 | }
56 |
57 | private ToolBar createToolBar(Pane containerPane, AutoResponsiveLayout autoResponsiveLayout) {
58 | ToolBar toolbar = new ToolBar();
59 |
60 | addButton(autoResponsiveLayout, toolbar, "1x1", 256, 256);
61 | addButton(autoResponsiveLayout, toolbar, "2x1", 512, 256);
62 | addButton(autoResponsiveLayout, toolbar, "1x2", 256, 512);
63 | addButton(autoResponsiveLayout, toolbar, "2x2", 512, 512);
64 |
65 | toolbar.getItems().add(new Separator());
66 |
67 | ToggleButton toggleButton2 = new ToggleButton("Balance Rows");
68 | toggleButton2.setOnAction((event) -> {
69 | autoResponsiveLayout.balanceRows = !autoResponsiveLayout.balanceRows;
70 | autoResponsiveLayout.layoutPane();
71 | });
72 |
73 | toolbar.getItems().add(toggleButton2);
74 |
75 | ToggleButton toggleButton1 = new ToggleButton("Pull Up Children");
76 | toggleButton1.setOnAction((event) -> {
77 | autoResponsiveLayout.pullUpChildren = !autoResponsiveLayout.pullUpChildren;
78 | autoResponsiveLayout.layoutPane();
79 | });
80 |
81 | toolbar.getItems().add(toggleButton1);
82 |
83 | ToggleButton toggleButton3 = new ToggleButton("Expand Child Width");
84 | toggleButton3.setOnAction((event) -> {
85 | autoResponsiveLayout.extendChildWidth = !autoResponsiveLayout.extendChildWidth;
86 | autoResponsiveLayout.layoutPane();
87 | });
88 |
89 | toolbar.getItems().add(toggleButton3);
90 |
91 | ToggleButton toggleButton4 = new ToggleButton("Expand Child Height");
92 | toggleButton4.setOnAction((event) -> {
93 | autoResponsiveLayout.extendChildHeight = !autoResponsiveLayout.extendChildHeight;
94 | autoResponsiveLayout.layoutPane();
95 | });
96 |
97 | toolbar.getItems().add(toggleButton4);
98 |
99 | toolbar.getItems().add(new Separator());
100 |
101 | ToggleButton toggleButton5 = new ToggleButton("Clear");
102 | toggleButton5.setOnAction((event) -> {
103 | autoResponsiveLayout.clear();
104 | autoResponsiveLayout.layoutPane();
105 | });
106 | toolbar.getItems().add(toggleButton5);
107 |
108 |
109 | return toolbar;
110 | }
111 |
112 | private void addButton(AutoResponsiveLayout autoResponsiveLayout, ToolBar toolbar, String buttonText, double minWidth, double minHeight) {
113 | Button buttonAdd = new Button(buttonText);
114 |
115 | buttonAdd.setOnAction((event) -> {
116 | Pane widgetPane = createWidgetPane(minWidth, minHeight);
117 | autoResponsiveLayout.addWidget(widgetPane);
118 | autoResponsiveLayout.layoutPane();
119 | });
120 |
121 | toolbar.getItems().add(buttonAdd);
122 | }
123 |
124 | private Pane createWidgetPane(double minWidth, double minHeight) {
125 | this.widgetCount++;
126 |
127 | Pane widgetPane = new Pane();
128 | widgetPane.setMinWidth(minWidth);
129 | widgetPane.setMinHeight(minHeight);
130 |
131 | StrokeType strokeType = StrokeType.INSIDE;
132 | StrokeLineJoin strokeLineJoin = StrokeLineJoin.MITER;
133 | StrokeLineCap strokeLineCap = StrokeLineCap.BUTT;
134 | double miterLimit = 10;
135 | double dashOffset = 0;
136 | List dashArray = null;
137 |
138 | BorderStrokeStyle borderStrokeStyle =
139 | new BorderStrokeStyle(
140 | strokeType,
141 | strokeLineJoin,
142 | strokeLineCap,
143 | miterLimit,
144 | dashOffset,
145 | dashArray
146 | );
147 |
148 |
149 | BorderStroke borderStroke =
150 | new BorderStroke(
151 | //Color.valueOf("08ff80"),
152 | Color.valueOf("#303F9F"),
153 | borderStrokeStyle,
154 | new CornerRadii(0),
155 | new BorderWidths(8)
156 | );
157 |
158 | Border border = new Border(borderStroke);
159 |
160 | Label label = new Label("" + this.widgetCount);
161 | label.setFont(Font.font("Arial", FontWeight.BOLD , FontPosture.REGULAR, 32));
162 | label.setLayoutX(20);
163 | label.setLayoutY(20);
164 | widgetPane.getChildren().add(label);
165 | widgetPane.setBorder(border);
166 | return widgetPane;
167 | }
168 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/media/MediaExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.media;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.Pane;
6 | import javafx.scene.media.Media;
7 | import javafx.scene.media.MediaPlayer;
8 | import javafx.scene.media.MediaView;
9 | import javafx.stage.Stage;
10 |
11 | import java.io.File;
12 | import java.net.MalformedURLException;
13 |
14 | /**
15 | * Shows a simple JavaFX Media, MediaPlayer and MediaView example, playing an MP4 video. Please note that the
16 | * video is downloaded from Pixabay.com. Please do not redistribute the video for any purpose. Download it from Pixabay
17 | * if you want to use it:
18 | *
19 | * https://pixabay.com/videos/golden-particles-overlay-decoration-48569/
20 | */
21 |
22 | public class MediaExample extends Application {
23 |
24 | public static void main(String[] args) {
25 | launch(args);
26 | }
27 |
28 | public void start(Stage primaryStage) throws MalformedURLException {
29 | File mediaFile = new File("assets/media/Golden-48569.mp4");
30 | Media media = new Media(mediaFile.toURI().toURL().toString());
31 |
32 | MediaPlayer mediaPlayer = new MediaPlayer(media);
33 |
34 | MediaView mediaView = new MediaView(mediaPlayer);
35 |
36 | Scene scene = new Scene(new Pane(mediaView), 1024, 800);
37 | primaryStage.setScene(scene);
38 | primaryStage.show();
39 |
40 | mediaPlayer.play();
41 |
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/menubutton/MenuButtonExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.menubutton;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.control.MenuButton;
7 | import javafx.scene.control.MenuItem;
8 | import javafx.scene.control.ToolBar;
9 | import javafx.scene.layout.VBox;
10 | import javafx.stage.Stage;
11 |
12 | /**
13 | * Shows a simple JavaFX MenuButton - and prints a text when a menu item from the button is selected.
14 | */
15 | public class MenuButtonExample extends Application {
16 |
17 | public static void main(String[] args) {
18 | launch(args);
19 | }
20 |
21 | @Override
22 | public void start(Stage primaryStage) {
23 |
24 | //First, simple example of creating a MenuButton
25 | MenuItem menuItem1 = new MenuItem("Action 1");
26 | MenuItem menuItem2 = new MenuItem("Action 2");
27 | MenuItem menuItem3 = new MenuItem("Action 3");
28 |
29 | menuItem1.setOnAction((event) -> { System.out.println("MenuItem1 activated"); });
30 | menuItem2.setOnAction((event) -> { System.out.println("MenuItem2 activated"); });
31 | menuItem3.setOnAction((event) -> { System.out.println("MenuItem3 activated"); });
32 |
33 | MenuButton menuButton = new MenuButton("Actions", null, menuItem1, menuItem2, menuItem3);
34 |
35 |
36 | //second, more elaborate example of how a MenuButton can be created, and configured via setter methods
37 | MenuButton menuButton2 = new MenuButton();
38 | menuButton2.setText("More Actions");
39 |
40 | MenuItem menuItem2_1 = new MenuItem("Action 1");
41 | MenuItem menuItem2_2 = new MenuItem("Action 2");
42 | MenuItem menuItem2_3 = new MenuItem("Action 3");
43 |
44 | menuItem2_1.setOnAction((event) -> { System.out.println("MenuItem2_1 activated"); });
45 | menuItem2_2.setOnAction((event) -> { System.out.println("MenuItem2_2 activated"); });
46 | menuItem2_3.setOnAction((event) -> { System.out.println("MenuItem2_3 activated"); });
47 |
48 | menuButton2.getItems().add(menuItem2_1);
49 | menuButton2.getItems().add(menuItem2_2);
50 | menuButton2.getItems().add(menuItem2_3);
51 |
52 | VBox vbox = new VBox(menuButton, menuButton2);
53 | Scene scene = new Scene(vbox);
54 | primaryStage.setScene(scene);
55 | primaryStage.setWidth (300);
56 | primaryStage.setHeight(300);
57 | primaryStage.show();
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/menubutton/MenuButtonFontExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.menubutton;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.MenuButton;
6 | import javafx.scene.control.MenuItem;
7 | import javafx.scene.layout.VBox;
8 | import javafx.scene.text.Font;
9 | import javafx.scene.text.FontWeight;
10 | import javafx.stage.Stage;
11 |
12 | /**
13 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
14 | */
15 | public class MenuButtonFontExample extends Application {
16 |
17 | public static void main(String[] args) {
18 | launch(args);
19 | }
20 |
21 | @Override
22 | public void start(Stage primaryStage) {
23 |
24 | MenuItem menuItem1 = new MenuItem("Option 1");
25 | MenuItem menuItem2 = new MenuItem("Option 2");
26 | MenuItem menuItem3 = new MenuItem("Option 3");
27 |
28 | MenuButton menuButton = new MenuButton("Options", null, menuItem1, menuItem2, menuItem3);
29 |
30 | Font font = Font.font("Courier New", FontWeight.BOLD, 36);
31 | menuButton.setFont(font);
32 |
33 | VBox vbox = new VBox(menuButton);
34 | Scene scene = new Scene(vbox);
35 | primaryStage.setScene(scene);
36 | primaryStage.setWidth (300);
37 | primaryStage.setHeight(300);
38 | primaryStage.show();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/menubutton/MenuButtonIconExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.menubutton;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.MenuButton;
6 | import javafx.scene.control.MenuItem;
7 | import javafx.scene.image.Image;
8 | import javafx.scene.image.ImageView;
9 | import javafx.scene.layout.VBox;
10 | import javafx.stage.Stage;
11 |
12 | import java.io.FileInputStream;
13 | import java.io.FileNotFoundException;
14 | import java.io.IOException;
15 |
16 | /**
17 | * Shows a simple JavaFX Button - and prints a text when the button is clicked.
18 | */
19 | public class MenuButtonIconExample extends Application {
20 |
21 | public static void main(String[] args) {
22 | launch(args);
23 | }
24 |
25 | @Override
26 | public void start(Stage primaryStage) throws IOException {
27 |
28 | //load MenuButton icon
29 | ImageView imageView = loadIcon();
30 |
31 | MenuItem menuItem1 = new MenuItem("User 1");
32 | MenuItem menuItem2 = new MenuItem("User 2");
33 |
34 | //create MenuButton - pass ImageView via constructor
35 | MenuButton menuButton1 = new MenuButton("Show User", imageView, menuItem1, menuItem2);
36 |
37 |
38 | MenuItem menuItem2_1 = new MenuItem("User 1");
39 | MenuItem menuItem2_2 = new MenuItem("User 2");
40 |
41 | //second example - pass ImageView via setGraphic()
42 | ImageView imageView2 = loadIcon();
43 | MenuButton menuButton2 = new MenuButton("Show User", null, menuItem2_1, menuItem2_2);
44 | menuButton2.setGraphic(imageView2);
45 |
46 |
47 | VBox vbox = new VBox(menuButton1, menuButton2);
48 | Scene scene = new Scene(vbox);
49 | primaryStage.setScene(scene);
50 | primaryStage.setWidth (300);
51 | primaryStage.setHeight(300);
52 | primaryStage.show();
53 | }
54 |
55 |
56 | private ImageView loadIcon() throws FileNotFoundException {
57 | FileInputStream input = new FileInputStream("assets/media/iconmonstr-user-1-32.png");
58 | Image image = new Image(input);
59 | ImageView imageView = new ImageView(image);
60 | return imageView;
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/pagination/PaginationExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.pagination;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Node;
5 | import javafx.scene.Scene;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.Pagination;
8 | import javafx.scene.layout.VBox;
9 | import javafx.scene.text.Font;
10 | import javafx.stage.Stage;
11 | import javafx.util.Callback;
12 |
13 | public class PaginationExample extends Application {
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | public static class MyPageFactory implements Callback {
19 | @Override
20 | public Node call(Integer param) {
21 | return new Label("Content for page " + param);
22 | }
23 | }
24 |
25 | @Override
26 | public void start(Stage primaryStage) {
27 | primaryStage.setTitle("JavaFX App");
28 |
29 | Pagination pagination = new Pagination();
30 | pagination.setPageCount(21);
31 | pagination.setCurrentPageIndex(3);
32 | pagination.setMaxPageIndicatorCount(3);
33 |
34 | pagination.setPageFactory(new Callback() {
35 | @Override
36 | public Node call(Integer param) {
37 | return null;
38 | }
39 | });
40 |
41 | pagination.setPageFactory((pageIndex) -> {
42 |
43 | Label label1 = new Label("Content for page with index: " + pageIndex);
44 | label1.setFont(new Font("Arial", 24));
45 |
46 | Label label2 = new Label("Main content of the page ...");
47 |
48 | return new VBox(label1, label2);
49 | });
50 |
51 |
52 |
53 | VBox vBox = new VBox(pagination);
54 | //HBox hBox = new HBox(button1, button2);
55 | Scene scene = new Scene(vBox, 960, 600);
56 |
57 | primaryStage.setScene(scene);
58 | primaryStage.show();
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/progressbar/ProgressBarExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.progressbar;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.ProgressBar;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | public class ProgressBarExample extends Application {
10 | public static void main(String[] args) {
11 | launch(args);
12 | }
13 |
14 | @Override
15 | public void start(Stage primaryStage) {
16 | primaryStage.setTitle("JavaFX App");
17 |
18 | ProgressBar progressBar = new ProgressBar(0);
19 |
20 | progressBar.setProgress(0.5);
21 |
22 | VBox vBox = new VBox(progressBar);
23 | Scene scene = new Scene(vBox, 960, 600);
24 |
25 | primaryStage.setScene(scene);
26 | primaryStage.show();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/properties/PropertyExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.properties;
2 |
3 | import javafx.application.Application;
4 | import javafx.beans.property.DoubleProperty;
5 | import javafx.beans.property.ReadOnlyDoubleProperty;
6 | import javafx.beans.value.ChangeListener;
7 | import javafx.beans.value.ObservableValue;
8 | import javafx.scene.Scene;
9 | import javafx.scene.layout.Pane;
10 | import javafx.stage.Stage;
11 |
12 | public class PropertyExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | public void start(Stage primaryStage) {
19 |
20 | Pane pane = new Pane();
21 |
22 | ReadOnlyDoubleProperty widthProperty = pane.widthProperty();
23 | widthProperty.addListener( new ChangeListener (){
24 | @Override
25 | public void changed(ObservableValue extends Number> observableValue, Number oldVal, Number newVal) {
26 | System.out.println("widthProperty changed from " + oldVal.doubleValue() + " to " + newVal.doubleValue());
27 | }
28 | });
29 |
30 |
31 | DoubleProperty prefWidthProperty = pane.prefWidthProperty();
32 | prefWidthProperty.addListener( (ObservableValue extends Number> prop, Number oldVal, Number newVal) -> {
33 | System.out.println("prefWidthProperty changed from " + oldVal.doubleValue() + " to " + newVal.doubleValue());
34 | });
35 |
36 | prefWidthProperty.set(123);
37 |
38 | Scene scene = new Scene(pane, 1024, 800, true);
39 | primaryStage.setScene(scene);
40 | primaryStage.setTitle("2D Example");
41 |
42 | primaryStage.show();
43 | }
44 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/scene/SceneCursorExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.scene;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Cursor;
5 | import javafx.scene.Scene;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | import static javafx.application.Application.launch;
10 |
11 | /**
12 | This example shows how to set a specific mouse cursor
13 | */
14 | public class SceneCursorExample extends Application {
15 |
16 | public static void main(String[] args) {
17 | launch(args);
18 | }
19 |
20 | @Override
21 | public void start(Stage primaryStage) {
22 | VBox vbox = new VBox();
23 | Scene scene = new Scene(vbox);
24 | //scene.setCursor(Cursor.DEFAULT);
25 |
26 | scene.setCursor(Cursor.CROSSHAIR);
27 | //scene.setCursor(Cursor.DISAPPEAR);
28 |
29 | //scene.setCursor(Cursor.CLOSED_HAND);
30 | //scene.setCursor(Cursor.HAND);
31 | //scene.setCursor(Cursor.OPEN_HAND);
32 |
33 | //scene.setCursor(Cursor.V_RESIZE);
34 | //scene.setCursor(Cursor.H_RESIZE);
35 |
36 | //scene.setCursor(Cursor.N_RESIZE);
37 | //scene.setCursor(Cursor.NE_RESIZE);
38 | //scene.setCursor(Cursor.E_RESIZE);
39 | //scene.setCursor(Cursor.SE_RESIZE);
40 | //scene.setCursor(Cursor.S_RESIZE);
41 | //scene.setCursor(Cursor.SW_RESIZE);
42 | //scene.setCursor(Cursor.W_RESIZE);
43 | //scene.setCursor(Cursor.NW_RESIZE);
44 |
45 | primaryStage.setTitle("Scene Example");
46 | primaryStage.setHeight(300);
47 | primaryStage.setWidth(300);
48 | primaryStage.setScene(scene);
49 | primaryStage.show();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/scrollpane/ScrollPaneExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.scrollpane;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.ScrollPane;
6 | import javafx.scene.image.Image;
7 | import javafx.scene.image.ImageView;
8 | import javafx.scene.layout.VBox;
9 | import javafx.stage.Stage;
10 |
11 | import java.io.FileInputStream;
12 | import java.io.FileNotFoundException;
13 |
14 | public class ScrollPaneExample extends Application {
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | @Override
20 | public void start(Stage primaryStage) throws FileNotFoundException {
21 | primaryStage.setTitle("JavaFX App");
22 |
23 | //String imagePath = "file://E:/video-projects/tutorials/java-switch-expression/assets/aerial-beverage-caffeine-972533.jpg";
24 |
25 | //choose the path for some large image on your hard disk here.
26 | String imagePath = "assets/media/abstract-5719221_640.jpg";
27 | ImageView imageView = new ImageView(new Image(new FileInputStream(imagePath)));
28 |
29 | //ScrollPane scrollPane = new ScrollPane(imageView);
30 | ScrollPane scrollPane = new ScrollPane();
31 | scrollPane.fitToWidthProperty().set(true);
32 | scrollPane.fitToHeightProperty().set(true);
33 | scrollPane.pannableProperty().set(true);
34 |
35 | scrollPane.hbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.AS_NEEDED);
36 | //scrollPane.hbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.NEVER);
37 | //scrollPane.hbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.ALWAYS);
38 | scrollPane.vbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.AS_NEEDED);
39 |
40 | scrollPane.setContent(imageView);
41 |
42 |
43 | VBox vBox = new VBox(scrollPane);
44 | //HBox hBox = new HBox(button1, button2);
45 | Scene scene = new Scene(vBox, 960, 600);
46 |
47 | primaryStage.setScene(scene);
48 | primaryStage.show();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/separator/SeparatorExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.separator;
2 |
3 | import javafx.application.Application;
4 | import javafx.geometry.Orientation;
5 | import javafx.scene.Scene;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.Separator;
8 | import javafx.scene.layout.VBox;
9 | import javafx.stage.Stage;
10 |
11 | public class SeparatorExample extends Application {
12 |
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | public void start(Stage primaryStage) {
18 |
19 | Label label1 = new Label("Component 1");
20 | Label label2 = new Label("Component 2");
21 |
22 | Separator separator = new Separator(Orientation.VERTICAL);
23 |
24 | VBox vBox = new VBox(label1, separator, label2);
25 | Scene scene = new Scene(vBox);
26 |
27 | primaryStage.setScene(scene);
28 | primaryStage.setTitle("JavaFX App");
29 |
30 | primaryStage.show();
31 | }
32 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/slider/SliderExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.slider;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Slider;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Stage;
8 |
9 | public class SliderExample extends Application {
10 | public static void main(String[] args) {
11 | launch(args);
12 | }
13 |
14 | @Override
15 | public void start(Stage primaryStage) {
16 | primaryStage.setTitle("JavaFX App");
17 |
18 | Slider slider = new Slider(0, 100, 0);
19 |
20 | slider.setMajorTickUnit(8);
21 | slider.setMinorTickCount(2);
22 |
23 | slider.setShowTickMarks(true);
24 | slider.setShowTickLabels(true);
25 |
26 | VBox vBox = new VBox(slider);
27 | Scene scene = new Scene(vBox, 960, 600);
28 |
29 | primaryStage.setScene(scene);
30 | primaryStage.show();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/splitmenubutton/SplitMenuButtonExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.splitmenubutton;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.MenuItem;
6 | import javafx.scene.control.SplitMenuButton;
7 | import javafx.scene.layout.VBox;
8 | import javafx.stage.Stage;
9 |
10 | public class SplitMenuButtonExample extends Application {
11 | public static void main(String[] args) {
12 | launch(args);
13 | }
14 |
15 | @Override
16 | public void start(Stage primaryStage) {
17 | primaryStage.setTitle("JavaFX App");
18 |
19 | SplitMenuButton button = new SplitMenuButton();
20 | button.setText("Click here!");
21 | button.setOnAction((e) -> {
22 | System.out.println("Button clicked!");
23 | System.out.println(e);
24 | System.out.println();
25 | });
26 |
27 | MenuItem choice1 = new MenuItem("Choice 1");
28 | MenuItem choice2 = new MenuItem("Choice 2");
29 | MenuItem choice3 = new MenuItem("Choice 3");
30 |
31 | choice1.setOnAction((e)-> {
32 | System.out.println("Choice 1 selected");
33 | });
34 | choice2.setOnAction((e)-> {
35 | System.out.println("Choice 2 selected");
36 | });
37 | choice3.setOnAction((e)-> {
38 | System.out.println("Choice 3 selected");
39 | });
40 |
41 | button.getItems().addAll(choice1, choice2, choice3);
42 |
43 | VBox vBox = new VBox(button);
44 | //HBox hBox = new HBox(button1, button2);
45 | Scene scene = new Scene(vBox, 960, 600);
46 |
47 | primaryStage.setScene(scene);
48 | primaryStage.show();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/splitmenubutton/SplitMenuButtonFontExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.splitmenubutton;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.MenuItem;
6 | import javafx.scene.control.SplitMenuButton;
7 | import javafx.scene.layout.VBox;
8 | import javafx.scene.text.Font;
9 | import javafx.scene.text.FontWeight;
10 | import javafx.stage.Stage;
11 |
12 | public class SplitMenuButtonFontExample extends Application {
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | @Override
18 | public void start(Stage primaryStage) {
19 | primaryStage.setTitle("JavaFX App");
20 |
21 | SplitMenuButton button = new SplitMenuButton();
22 | button.setText("Click here!");
23 |
24 | Font font = Font.font("Courier New", FontWeight.BOLD, 36);
25 | button.setFont(font);
26 |
27 | button.setOnAction((e) -> {
28 | System.out.println("Button clicked!");
29 | System.out.println(e);
30 | System.out.println();
31 | });
32 |
33 | MenuItem choice1 = new MenuItem("Choice 1");
34 | MenuItem choice2 = new MenuItem("Choice 2");
35 | MenuItem choice3 = new MenuItem("Choice 3");
36 |
37 | choice1.setOnAction((e)-> {
38 | System.out.println("Choice 1 selected");
39 | });
40 | choice2.setOnAction((e)-> {
41 | System.out.println("Choice 2 selected");
42 | });
43 | choice3.setOnAction((e)-> {
44 | System.out.println("Choice 3 selected");
45 | });
46 |
47 | button.getItems().addAll(choice1, choice2, choice3);
48 |
49 | VBox vBox = new VBox(button);
50 | //HBox hBox = new HBox(button1, button2);
51 | Scene scene = new Scene(vBox, 960, 600);
52 |
53 | primaryStage.setScene(scene);
54 | primaryStage.show();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/splitpane/SplitPaneExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.splitpane;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.control.SplitPane;
7 | import javafx.scene.layout.VBox;
8 | import javafx.stage.Stage;
9 |
10 | public class SplitPaneExample extends Application {
11 |
12 | public static void main(String[] args) {
13 | launch(args);
14 | }
15 |
16 | public void start(Stage primaryStage) {
17 |
18 | SplitPane splitPane = new SplitPane();
19 |
20 | VBox leftControl = new VBox(new Label("Left Control"));
21 | VBox midControl = new VBox(new Label("Mid Control"));
22 | VBox rightControl = new VBox(new Label("Right Control"));
23 |
24 | splitPane.getItems().addAll(leftControl, midControl, rightControl);
25 |
26 | Scene scene = new Scene(splitPane);
27 |
28 | primaryStage.setScene(scene);
29 | primaryStage.setTitle("JavaFX App");
30 |
31 | primaryStage.show();
32 | }
33 | }
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/AutoShutDownExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.application.Platform;
5 | import javafx.scene.Scene;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.layout.VBox;
8 | import javafx.stage.Stage;
9 |
10 | public class AutoShutDownExample extends Application {
11 |
12 | public static void main(String[] args) {
13 | launch(args);
14 | }
15 |
16 | @Override
17 | public void start(Stage primaryStage) throws InterruptedException {
18 |
19 | Label label = new Label("This app will shut down automatically");
20 | VBox vbox = new VBox(label);
21 |
22 | Scene scene = new Scene(vbox);
23 |
24 | primaryStage.setScene(scene);
25 | primaryStage.setWidth(300);
26 | primaryStage.setHeight(100);
27 | primaryStage.show();
28 |
29 |
30 | new Thread( () -> {
31 | try {
32 | Thread.sleep(5000);
33 | } catch (InterruptedException e) {
34 | e.printStackTrace();
35 | }
36 |
37 | Platform.runLater(() -> {
38 | primaryStage.close();
39 | });
40 |
41 | }).start();
42 |
43 |
44 | //Thread.sleep(5000);
45 |
46 |
47 | //primaryStage.close();
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/FullScreenStageExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.VBox;
6 | import javafx.stage.Stage;
7 |
8 | /**
9 | * Shows a Stage in full screen mode. Use ESC key to exit full screen mode.
10 | */
11 | public class FullScreenStageExample extends Application {
12 |
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 | @Override
18 | public void start(Stage primaryStage) {
19 |
20 | VBox vbox = new VBox();
21 | Scene scene = new Scene(vbox);
22 |
23 | //Notice that the Stage title is not visible in full screen mode
24 | primaryStage.setTitle("Full Screen Window Title");
25 | primaryStage.setScene(scene);
26 | primaryStage.setFullScreen(true);
27 |
28 | primaryStage.show();
29 | }
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/MultipleStagesExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.VBox;
6 | import javafx.stage.Stage;
7 |
8 | /**
9 | * This example shows two Stages at the same time.
10 | * Please keep in mind that the second Stage is not shown in modal mode - meaning the second Stage
11 | * does not block access to the first Stage.
12 | *
13 | */
14 | public class MultipleStagesExample extends Application {
15 |
16 | public static void main(String[] args) {
17 | launch(args);
18 | }
19 |
20 | @Override
21 | public void start(Stage primaryStage) {
22 |
23 | VBox vbox = new VBox();
24 | Scene scene = new Scene(vbox);
25 |
26 | primaryStage.setTitle("JavaFX App");
27 | primaryStage.setHeight(200);
28 | primaryStage.setWidth(200);
29 | primaryStage.setScene(scene);
30 | primaryStage.show();
31 |
32 | Stage stage = new Stage();
33 | stage.setTitle("JavaFX Stage Window Title");
34 | stage.setX(500);
35 | stage.setY(500);
36 |
37 | stage.setWidth(600);
38 | stage.setHeight(300);
39 |
40 | stage.showAndWait();
41 | }
42 |
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/MultipleStagesModalExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Button;
6 | import javafx.scene.layout.VBox;
7 | import javafx.stage.Modality;
8 | import javafx.stage.Stage;
9 |
10 | /**
11 | * This example shows two Stages at the same time - in modal mode.
12 | * This means, that the second Stage blocks access to the first while the second Stage is visible/open.
13 | * Notice how you cannot click the Button that is visible in the primary Stage while the secondary Stage is
14 | * open.
15 | *
16 | */
17 | public class MultipleStagesModalExample extends Application {
18 |
19 | public static void main(String[] args) {
20 | launch(args);
21 | }
22 |
23 | @Override
24 | public void start(Stage primaryStage) {
25 |
26 | Button button = new Button("Click me if you can...");
27 | button.setOnAction((event) -> {
28 | System.out.println("Button clicked");
29 | });
30 |
31 | VBox vbox = new VBox(button);
32 | Scene scene = new Scene(vbox);
33 |
34 | primaryStage.setTitle("Primary Stage");
35 | primaryStage.setX(250);
36 | primaryStage.setY(250);
37 | primaryStage.setHeight(500);
38 | primaryStage.setWidth(500);
39 | primaryStage.setScene(scene);
40 | primaryStage.show();
41 |
42 | Stage stage = new Stage();
43 | stage.setTitle("Secondary Stage - in Modal Mode");
44 | stage.setX(300);
45 | stage.setY(300);
46 | stage.setWidth(300);
47 | stage.setHeight(300);
48 |
49 | stage.initOwner(primaryStage);
50 | //stage.initModality(Modality.NONE);
51 | stage.initModality(Modality.WINDOW_MODAL);
52 | //stage.initModality(Modality.APPLICATION_MODAL);
53 |
54 |
55 | stage.showAndWait();
56 | }
57 |
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/StageDecorationExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.VBox;
6 | import javafx.stage.Stage;
7 | import javafx.stage.StageStyle;
8 |
9 | /**
10 | * This example displays a Stage without any decorations - meaning without any "close" or "minimize" buttons,
11 | * and no top title bar. You can play with the other Stage styles by commenting the other options in and out.
12 | *
13 | */
14 | public class StageDecorationExample extends Application {
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | @Override
20 | public void start(Stage primaryStage) {
21 |
22 | VBox vbox = new VBox();
23 | Scene scene = new Scene(vbox);
24 | primaryStage.setTitle("This title is not visible");
25 | primaryStage.setScene(scene);
26 |
27 | //primaryStage.initStyle(StageStyle.DECORATED);
28 | primaryStage.initStyle(StageStyle.UNDECORATED);
29 | //primaryStage.initStyle(StageStyle.TRANSPARENT);
30 | //primaryStage.initStyle(StageStyle.UNIFIED);
31 | //primaryStage.initStyle(StageStyle.UTILITY);
32 |
33 | primaryStage.show();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/StageExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.VBox;
6 | import javafx.stage.Stage;
7 |
8 | /**
9 | * Shows a simple Stage with a title, X,Y position and width and height.
10 | */
11 | public class StageExample extends Application {
12 |
13 | public static void main(String[] args) {
14 | launch(args);
15 | }
16 |
17 |
18 | @Override
19 | public void start(Stage primaryStage) {
20 | VBox vbox = new VBox();
21 | Scene scene = new Scene(vbox);
22 |
23 | primaryStage.setTitle("Window Title");
24 | primaryStage.setX(250);
25 | primaryStage.setY(250);
26 | primaryStage.setHeight(200);
27 | primaryStage.setWidth(200);
28 | primaryStage.setScene(scene);
29 | primaryStage.show();
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/stage/StageKeyboardEventsExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.stage;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.input.KeyEvent;
7 | import javafx.scene.layout.VBox;
8 | import javafx.stage.Stage;
9 |
10 | public class StageKeyboardEventsExample extends Application {
11 |
12 | public static void main(String[] args) {
13 | launch(args);
14 | }
15 |
16 | @Override
17 | public void start(Stage primaryStage) throws InterruptedException {
18 |
19 | Label label = new Label("This app will shut down automatically");
20 | VBox vbox = new VBox(label);
21 |
22 | Scene scene = new Scene(vbox);
23 |
24 | primaryStage.setScene(scene);
25 | primaryStage.setWidth(300);
26 | primaryStage.setHeight(100);
27 | primaryStage.show();
28 |
29 | primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, (event) -> {
30 | System.out.println("Key pressed: " + event.toString());
31 |
32 | switch(event.getCode().getCode()) {
33 | case 27 : { // 27 = ESC key
34 | primaryStage.close();
35 | break;
36 | }
37 | case 10 : { // 10 = Return
38 | primaryStage.setWidth( primaryStage.getWidth() * 2);
39 | }
40 | default: {
41 | System.out.println("Unrecognized key");
42 | }
43 | }
44 | });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/tableview/Customer.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.tableview;
2 |
3 | public class Customer {
4 | private String customerNo = null;
5 | private String firstName = null;
6 | private String lastName = null;
7 |
8 |
9 | public Customer(String customerNo, String firstName, String lastName){
10 | this.customerNo = customerNo;
11 | this.firstName = firstName;
12 | this.lastName = lastName;
13 | }
14 |
15 | public String getCustomerNo() {
16 | return customerNo;
17 | }
18 |
19 | public void setCustomerNo(String customerNo) {
20 | this.customerNo = customerNo;
21 | }
22 |
23 | public String getFirstName() {
24 | return firstName;
25 | }
26 |
27 | public void setFirstName(String firstName) {
28 | this.firstName = firstName;
29 | }
30 |
31 | public String getLastName() {
32 | return lastName;
33 | }
34 |
35 | public void setLastName(String lastName) {
36 | this.lastName = lastName;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/tableview/Person.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.tableview;
2 |
3 | public class Person {
4 |
5 | private String firstName = null;
6 | private String lastName = null;
7 |
8 | private String category = null;
9 |
10 | private boolean isXyz = true;
11 |
12 | public Person() {
13 | }
14 |
15 | public Person(String firstName, String lastName) {
16 | this.firstName = firstName;
17 | this.lastName = lastName;
18 | }
19 |
20 | public Person(String firstName, String lastName, String category, boolean isXyz) {
21 | this.firstName = firstName;
22 | this.lastName = lastName;
23 | this.category = category;
24 | this.isXyz = isXyz;
25 | }
26 |
27 | public String getFirstName() {
28 | return firstName;
29 | }
30 |
31 | public void setFirstName(String firstName) {
32 | this.firstName = firstName;
33 | }
34 |
35 | public String getLastName() {
36 | return lastName;
37 | }
38 |
39 | public void setLastName(String lastName) {
40 | this.lastName = lastName;
41 | }
42 |
43 | public String toString() {
44 | return "{ firstName: '" + this.firstName + ", lastName: " + this.lastName + " }";
45 | }
46 |
47 |
48 | public String getCategory() {
49 | return this.category;
50 | }
51 |
52 | public void setCategory(String category) {
53 | this.category = category;
54 | }
55 |
56 | public Boolean getIsXyz() {
57 | return this.isXyz;
58 | }
59 |
60 | public void setIsXyz(Boolean isXyz) {
61 | this.isXyz = isXyz;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/tableview/TableViewCustomRenderingExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.tableview;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.TableCell;
6 | import javafx.scene.control.TableColumn;
7 | import javafx.scene.control.TableView;
8 | import javafx.scene.control.cell.PropertyValueFactory;
9 | import javafx.scene.layout.VBox;
10 | import javafx.stage.Stage;
11 |
12 | public class TableViewCustomRenderingExample extends Application {
13 |
14 | public static void main(String[] args) {
15 | launch(args);
16 | }
17 |
18 | @Override
19 | public void start(Stage primaryStage) {
20 |
21 | TableView tableView = new TableView();
22 |
23 | TableColumn customerColumn = new TableColumn<>("Customer");
24 |
25 | customerColumn.setCellValueFactory(new PropertyValueFactory<>("firstName"));
26 | customerColumn.setCellFactory((tableColumn) -> {
27 | TableCell tableCell = new TableCell<>() {
28 | @Override
29 | protected void updateItem(String item, boolean empty) {
30 | super.updateItem(item, empty);
31 |
32 | this.setText(null);
33 | this.setGraphic(null);
34 |
35 | if(!empty){
36 | this.setText(item.toUpperCase());
37 | }
38 | }
39 | };
40 |
41 | return tableCell;
42 | });
43 |
44 | tableView.getColumns().add(customerColumn);
45 |
46 | tableView.getItems().add(new Customer("007", "Jane", "Deer"));
47 | tableView.getItems().add(new Customer("006", "John", "Doe"));
48 | tableView.getItems().add(new Customer("008", "Mack", "Alamo"));
49 |
50 | VBox vbox = new VBox(tableView);
51 | Scene scene = new Scene(vbox);
52 |
53 | primaryStage.setScene(scene);
54 | primaryStage.setTitle("JavaFX TableView Example");
55 |
56 | primaryStage.show();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/tableview/TableViewEditableExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.tableview;
2 |
3 | import javafx.application.Application;
4 | import javafx.beans.property.ReadOnlyBooleanWrapper;
5 | import javafx.scene.Scene;
6 | import javafx.scene.control.TableCell;
7 | import javafx.scene.control.TableColumn;
8 | import javafx.scene.control.TableView;
9 | import javafx.scene.control.cell.CheckBoxTableCell;
10 | import javafx.scene.control.cell.ComboBoxTableCell;
11 | import javafx.scene.control.cell.PropertyValueFactory;
12 | import javafx.scene.control.cell.TextFieldTableCell;
13 | import javafx.scene.layout.VBox;
14 | import javafx.stage.Stage;
15 |
16 | import java.io.FileNotFoundException;
17 |
18 | public class TableViewEditableExample extends Application {
19 |
20 | public static void main(String[] args) {
21 | launch(args);
22 | }
23 |
24 | @Override
25 | public void start(Stage primaryStage) throws InterruptedException, FileNotFoundException {
26 |
27 | TableView tableView = new TableView();
28 | tableView.setEditable(true);
29 |
30 | TableColumn column1 = new TableColumn<>("First Name");
31 | column1.setCellValueFactory(new PropertyValueFactory<>("firstName"));
32 |
33 | TableColumn column2 = new TableColumn<>("Last Name");
34 | column2.setCellValueFactory(new PropertyValueFactory<>("lastName"));
35 | column2.setCellFactory(TextFieldTableCell.forTableColumn());
36 |
37 | TableColumn column3 = new TableColumn<>("Category");
38 | column3.setCellValueFactory(new PropertyValueFactory<>("category"));
39 | column3.setCellFactory(ComboBoxTableCell.forTableColumn("Category 1", "Category 2"));
40 |
41 | TableColumn column4 = new TableColumn<>("Is XYZ");
42 | column4.setCellValueFactory( cellData -> new ReadOnlyBooleanWrapper(cellData.getValue().getIsXyz()));
43 | column4.setCellFactory(CheckBoxTableCell.forTableColumn(column4));
44 |
45 |
46 | tableView.getColumns().add(column1);
47 | tableView.getColumns().add(column2);
48 | tableView.getColumns().add(column3);
49 | tableView.getColumns().add(column4);
50 |
51 | tableView.getItems().add(new Person("John" , "Doe" , null, false));
52 | tableView.getItems().add(new Person("Jane" , "Deer" , "Category 1", true));
53 | tableView.getItems().add(new Person("Dinesh", "Gupta", "Category 2", true));
54 |
55 | VBox vbox = new VBox(tableView);
56 | Scene scene = new Scene(vbox);
57 |
58 | primaryStage.setScene(scene);
59 | primaryStage.setTitle("JavaFX Editable TableView Example");
60 |
61 | primaryStage.show();
62 |
63 | System.out.println("Opened");
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/tableview/TableViewExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.tableview;
2 |
3 | import javafx.application.Application;
4 | import javafx.scene.Scene;
5 | import javafx.scene.control.TableColumn;
6 | import javafx.scene.control.TableView;
7 | import javafx.scene.control.cell.PropertyValueFactory;
8 | import javafx.scene.layout.VBox;
9 | import javafx.stage.Stage;
10 |
11 | import java.io.FileNotFoundException;
12 |
13 | public class TableViewExample extends Application {
14 |
15 | public static void main(String[] args) {
16 | launch(args);
17 | }
18 |
19 | @Override
20 | public void start(Stage primaryStage) throws InterruptedException, FileNotFoundException {
21 |
22 | TableView tableView = new TableView();
23 |
24 | TableColumn column1 = new TableColumn<>("First Name");
25 | column1.setCellValueFactory(new PropertyValueFactory<>("firstName"));
26 |
27 | TableColumn column2 = new TableColumn<>("Last Name");
28 | column2.setCellValueFactory(new PropertyValueFactory<>("lastName"));
29 |
30 | tableView.getColumns().add(column1);
31 | tableView.getColumns().add(column2);
32 |
33 | tableView.getItems().add(new Person("John", "Doe"));
34 | tableView.getItems().add(new Person("Jane", "Deer"));
35 |
36 | VBox vbox = new VBox(tableView);
37 | Scene scene = new Scene(vbox);
38 |
39 | primaryStage.setScene(scene);
40 | primaryStage.setTitle("JavaFX TableView Example");
41 |
42 | primaryStage.show();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/jenkov/javafx/tableview/TableViewMapDataItemsExample.java:
--------------------------------------------------------------------------------
1 | package com.jenkov.javafx.tableview;
2 |
3 | import javafx.application.Application;
4 | import javafx.collections.FXCollections;
5 | import javafx.collections.ObservableList;
6 | import javafx.scene.Scene;
7 | import javafx.scene.control.TableColumn;
8 | import javafx.scene.control.TableView;
9 | import javafx.scene.control.cell.MapValueFactory;
10 | import javafx.scene.layout.VBox;
11 | import javafx.stage.Stage;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | public class TableViewMapDataItemsExample extends Application {
17 |
18 | public static void main(String[] args) {
19 | launch(args);
20 | }
21 |
22 | @Override
23 | public void start(Stage primaryStage) {
24 |
25 | TableView tableView = new TableView();
26 |
27 | ObservableList