While you are not forced to use IntelliJ over Eclipse or any other IDE, it is recommended that you use IntelliJ in conjunction with the SceneBuilder if you plan on following along with this tutorial.
While you are not forced to use IntelliJ over Eclipse or any other IDE, it is recommended over Eclipse.
1. Navigate to the [official site](https://www.jetbrains.com/idea/download/#section=windows) for IntelliJ IDEA.
2. Download the **free** community edition.
3. Wait about 5 seconds the download to start, and then run the executable after it is finished downloading. (For Mac, it will be a `.dmg` file, and for Windows, a `.exe` file.
...
...
@@ -13,6 +12,17 @@ While you are not forced to use IntelliJ over Eclipse or any other IDE, it is re
8. If you are installing IntelliJ for the first time, you can choose `Do not import settings` and then click `OK`.
9. Customize your IntelliJ accordingly.
# Installing Eclipse (macOS/Windows)
1. Navigate to eclipse.org.
2. Click the download button in the upper right of the webpage.
3. Click the bright-orange 'Download 64 bit' button the left side of the screen.
4. Click the bright-orange 'Download' button.
5. Run the installer.
- You may be informed that you need a Java Development Kit. If that is the case, click the 'More Info' button and download the JDK from the site the button sends you to.
6. Install the Eclipse IDE For Java Developers, the top option.
7. Accept the licenses, the installation will take a while.
8. When the installation is complete, launch Eclipse.
# Installing JavaFX Scene Builder (macOS/Windows)
1. Navigate to the [official site](https://gluonhq.com/products/scene-builder/#download) for the JavaFX Scene Builder.
...
...
@@ -28,23 +38,45 @@ This tutorial will walk you through creating a basic JavaFX application. The end
## Using SceneBuilder with IntelliJ IDEA
Your life will be infinitely easier if you just use IntelliJ IDEA in conjunction with JavaFX Scene Builder.
1. Open IntelliJ.
2. Click `Create New Project`.
3. Create a new JavaFX application.
4. Give it a name, and a location.
5. Now that your project has been created, click on `File` in the upper-left corner of the screen.
6. Click `Settings`, and then `Languages and Frameworks`.
4. Now that your project has been created, click on `File` in the upper-left corner of the screen.
5. Click `Settings`, and then `Languages and Frameworks`.
- If you are running IntelliJ IDEA on a Mac, you instead go to `IntelliJ IDEA -> Preferences -> Languages and Frameworks`.
7. Click on `JavaFX`.
8. Set the path to where your `SceneBuilder.exe` (on Windows) or `SceneBuilder.app` (on macOS) is installed at.
9. Click `OK`.
10. IntelliJ should have generated three files within the `src` directory of your project, within a package called `sample`.
11. Rename this `sample` package to `app`.
6. Click on `JavaFX`.
7. Set the path to where your `SceneBuilder.exe` (on Windows) or `SceneBuilder.app` (on macOS) is installed at.
8. Click `OK`.
9. IntelliJ should have generated three files within the `src` directory of your project, within a package called `sample`.
10. Rename this `sample` package to `app`.
- Make sure all occurrences are renamed to `app`.
12. Find the file entitled `sample.fxml`, and rename it to `home.fxml`.
13. Right click on the file, and click the option that says `Open In SceneBuilder`.
11. Find the file entitled `sample.fxml`, and rename it to `home.fxml`.
12. Right click on the file, and click the option that says `Open In SceneBuilder`.
- This is the file that holds all of the code for the look of your application. Now that you've opened it up directly, whenever you make changes within the SceneBuilders, those changes will also be reflected with `home.fxml` whenever you click save.
## Using JavaFX Scene Builder with Eclipse
Eclipse does not natively support the JavaFX Scene Builder in the way that IntelliJ IDEA does. To get around this, you are going to have to manually install the JavaFX plugin for Eclipse - which is why it is recommended you just use IntelliJ IDEA instead. Even when the plugin is installed, life is made more difficult as `.fxml` projects are not automatically generated in conjunction with new JavaFX projects. In conclusion: make your life easier and just use IntelliJ IDEA.
1. Open Eclipse.
2. Go to `Help` in the navigation bar.
3. Click `Install New Software`.
4. In the 'Work With' text box, paste in the following link: http://download.eclipse.org/efxclipse/updates-released/3.6.0/site
5. Click `Add...`, and give it the following name: `e(fx)clipse`.
6. Click OK, and and now select both of the shown checkboxes.
7. Click `Next >`, and wait for e(fx)clipse to finish installing.
8. Click `Finish`.
9. When the installation is finished, Eclipse will prompt you for a restart. Do that.
10. Now, you will be able to create new JavaFX project from the 'New Project' wizard of Eclipse. Create a new JavaFX project.
11. Within the `src` directory of your new project, a package called `application` will have been generated. `Main.java` is the driver code. Create a new file called `home.fxml` within this package.
12. Right-click your newly created file and click `Open with SceneBuilder`.
- If Eclipse tells yo u that opening the file with SceneBuilder failed, here are the steps to fix that:
- Go to `Window` in the navigation bar, and then `Preferences`.
- Go to JavaFX, and then set the SceneBuilder executable to wherever your `SceneBuilder.exe` is saved at. Apply and Close.
- Now, you should be able to open SceneBuilder from Eclipse!
## Building your first application
1. Now that the SceneBuilder is open, we can talk about the different components of it:
9. Now, copy and paste the same function into the new `SecondScreenController`, changing out `secondScreen.fxml` for `home.fxml`.
10. Link `secondScreen.fxml` to the `SecondScreenController` as we did previously in Step 11 of "Registering Event Handlers."
11. You should be able to move back and forth between the two scenes now!
### Passing Data Between Scenes
As of right now, our application doesn't have any data confined to it, nor does it do anything of interest. Let's throw some data onto the initial screen, and learn how to transfer that data around to other scenes in the application so that it does something a little bit more interesting.
1. Open up `home.fxml` again.
2. Add three checkboxes to the center of the `AnchorPane`, and label them as whatever you want.
3. Assign each of these checkbox an ID, something simple like `checkbox1`, `checkbox2`, etc...
4. Make you sure you create the `@FXML private CheckBox checkbox[number]` to correspond with each of the created elements in your `HomeController.java`, and import the necessary class (`javafx.scene.control.CheckBox`).
5. In the `Properties` tab of the `Inspector`, let's set the first checkbox to be auto-selected.
6. placeholder
7. Open up `secondScreen.fxml`.
8. Remove the `Label` from the `AnchorPane on top`, and add 4 new `Label`s: