In a previous video on this channel
I actually showed you how to set up and
configure JavaFX for JDK Version 11.
Now that we've done that, I want
to go through the process and show you
how to configure a new project
to use the global setup of JavaFX,
that we set up again for JDK 11.
So let's make a start on that,
and we're gonna be using the IntelliJ IDEA IDE.
So, let's get started.
(upbeat music)
So IntelliJ's got a plugin that
supports JavaFX applications.
When you instal IntelliJ the plugin was
installed and enabled by default,
so we're gonna go ahead and use that in this project.
So you click on 'Create New Project' as you normally would.
And you'll notice this option here to the left,
you've probably seen that before.
We've got Java which we've used traditionally,
but there's also this JavaFX.
Make sure your Project SDK is set to 11 in this case,
click on 'Next'
We need to define a name,
so I'm gonna call this one HelloWorldFX.
So effectively we're gonna be creating
our first Hello World project,
but using JafaFX.
So we're going to click on 'Finish' now,
and create the project.
Now, click over to 'Main' and you see right away
that there's some errors.
So we've got the errors and that's because
the JavaFx library is now no longer part of the JDK.
So we need to actually configure it,
and set it up so that the Global Library that we've
defined is used for this project.
So you'll need to do the following steps
every time you create a new JavaFX project,
if you're running JDK 11.
First things first, we're gonna click on the project,
right click and select 'Open Module Settings'.
Come up to 'Project',
we want to firstly check the Project SDK
is correctly configured,
11 in my case.
The Project language level needs to be
configured the same as the Project SDK,
so the same number.
In the case of JDK 11 obviously I'm selecting 11,
and by doing that, if you come over to modules,
you should then find that because we were
using the Project default that that's
now also set to version 11.
The next step we also need to do,
is go to Global Libraries.
Then you need to right click here,
we need to click on 'Add to Modules'.
So what that's doing is adding this module that
we've defined as global module,
we're telling IntelliJ that we want to use
that in this particular IntelliJ project.
So click on that and once that's set up
it confirms that it's going to be
added to the selected modules,
which in this case is the name of our project.
Click 'OK',
click 'OK' again.
Now you can see that that has actually fixed
some of the import errors,
we're now no longer getting any errors,
but you'll find that if you go to run this now--
I'll just expand this out so we can see
it a little bit better.
You will find that we get an error.
So I'll click on run.
We've got an error there:
JavaFX runtime components are missing.
Basically what we've done so far
is we've added the Global Library to our
JDK 11 application but at this stage it's not working
because we need to configure it so that it works
when we're running the application as well.
So what we need to do to actually fix this,
is we need to add a module-info.java file
so that we have defined the JafaFX control
so that it'll actually work.
And the way we do that is that we
right click the source folder.
Noticing that I'm not clicking on the package name,
we're clicking at source level.
Right click, select 'New'.
We need to select 'module-info.java',
and that should open up a little file like this,
and by the way, if you don't see the option here
when you right click and select 'New',
if you don't see an option there,
we won't see see Module Info there now because
you've already created it,
but prior to that--
Actually, what I'll do is I'll just undo it.
Just to show you, so cancel that.
Right click again,
'New'.
So if you don't see this module-info.java package
what that means is you haven't correctly configured
in Project the Project language level,
so 11 is either not set there,
or set there.
Because once you do that,
that option should come up for you automatically.
So I'm gonna go ahead and create that file again.
Module-info.java.
And what we now need to do is add a few commands here,
so that JavaFX will work.
So first off I'm gonna type is
requires
javafx
dot
fxml
that's number one,
then the second one is 'requires javafx.controls'.
And the last line we need to add then is
opens, and we're gonna go 'sample'.
Sample is the name that we've defined here,
basically the package name.
So we're specifying that there.
At that point we will now find that this application
would work for JDK 11.
So let's actually give that a test run.
And you can see now we've got basically a GUI interface,
there's no controls on it at this stage,
and that's normal because we haven't added any
controls to the application yet.
Bottom line is that that's now working,
we've correctly configured the JavaFX Global Library,
we've configured it and added it to this project.
We've also added the module-info.java file,
so at this point in time it's now working under JDK 11.
Alright, so thanks for watching.
If you've got questions leave a comment,
if you're ready for the next programming-specific video
click on the link up here in the top left hand
corner of your screen.
To look at non-coding programming-related questions,
click on the link down the bottom
left hand corner of your screen.
Feel free to subscribe by clicking on the link up here,
and I'll see you in another video.