JavaFX is a Java toolkit for creating visually pleasing apps. Java is a computer programming language that is used to write apps for most any Operating System (OS) that you can think of. That includes Windows, MacOS, iOS, Android, Red Hat, Solaris, AIX, FreeBSD, and many others that exist in the wild. JavaFX handles the windows, buttons, pictures, and graphics for those Java apps.
Never written a JavaFX or even a Java program before? Then, this is a good first app. All it does is create a window that shows the message, “Hello World!”
Note: This is a good tutorial to start with for the first-time programmer. If you are looking for a good learning path for the new programmer, check out my JavaFX learning path for new developers.
The first thing you need to do, is install a current version of Eclipse. Eclipse is an Integrated Development Environment, more commonly called an IDE.
IDE’s are the standard tool for developing most software these days. You can write an entire application using just Notepad or TextEdit. However, that is painful, and mostly a waste of time. You’ll want a decent IDE, such as Eclipse.
In the Java realm, three IDE’s reign supreme. There is Eclipse, which I prefer. There is Netbeans, that Oracle maintains. There is also, the costly IntelliJ, that many Java developers swear by. Eclipse and Netbeans are free, so you’ll probably want to stick to one of those for now. Like I said, I like Eclipse for my JavaFX development.
If you are a first time developer, you’ll need a copy of the Java Development Kit (JDK). This is different than the Java Runtime Environment (JRE). There are many more goodies in the JDK than the JRE for anyone looking to create Java applications. It’ll bee a little intimidating at first, but go over to Oracle’s site, and grab a current version of the JDK and install it on your computer.
Eclipse is found over at eclipse.org. Just get the standard Java version of the IDE.
Finally, you’ll need to install the JavaFX plugin for Eclipse. It is called e(fx)clipse. Yes. That is really it’s name. I don’t try pronouncing it. Things work out better that way.
You can get e(fx)clipse installed in your Eclipse IDE by following the instructions on the e(fx)clipse home page.
Once you have the JDK, Eclipse, and e(fx)clipse, you are ready to do some JavaFX programming! As stated above, let’s create a JavaFX Hello World app.
Start be creating a new JavaFX project. You can do that by browsing the menu and opening the New Project wizard.
This opens the New Project wizard. Since you’ve install e(fx)clispe, you have the JavaFX Project as one of your options. Select it, and click Next.
Give it the name of hello-world and click Finished.
Now your package explorer on the left, should look something like this.
Click on the Main.java file, and let’s make some minor modifications. Currently, Main.java has the following yucky code.
They managed to create a default JavaFX app that does less than a Hello World app. That’s impressive and depressing, all at the same time. Let’s fix the code so it at least says something when the app is run.
Paste the following JavaFX code in to replace the old code.
Now let’s run the new Hello World app. Select run Java Application by first clicking on the Main.java file, then browse the menu to select Run as Java Application.
Run->Run As->Java Application
You should get a JavaFX window with the words, Hello World!
Welcome to the world of JavaFX programming!
Remember, if you are new to Java programming, or computer programming in general. I’ve written a learning path with plenty of links to articles and tutorials to get you up-to-speed on writing your own JavaFX applications. Anyone who’s determined enough and willing to put in the practice can become a JavaFX developer. It will take time and study, but don’t give up.