What is JavaFX?

JavaFX is a set of software APIs and tools that delivers desktop applications and rich internet applications (RIAs) that can run most anywhere Java runs. JavaFX applications run on Windows, MacOS, iOS, Android, Linux, and many other operating systems. JavaFX replaces Swing and the older AWT as Java SE’s GUI. Oracle is actively improving JavaFX, and likely will for many years to come.

That’s the simple version of what JavaFX is, but not a complete one. After reading the definition of JavaFX, you might still find yourself scratching your head and asking, What is JavaFX?

Obviously, this whole site is dedicated to answering that one question.

Continue reading “What is JavaFX?”

Drawing Squares and Circles in JavaFX

JavaFX Shapes
Drawing shapes in JavaFX is easy.

JavaFX is all about graphics and drawing. Sure JavaFX can do great layouts, but if you need to visualize results, add images to layouts, or display data, JavaFX has all the tools you’ll need. Even games are written using JavaFX.

If you don’t know where to start learning JavaFX graphics capabilities, start with this tutorial. This tutorial explains how to draw JavaFX circles and squares after laying out your JavaFX UI using Scene Builder. It may not be glamorous, but it is a beginning. Continue reading “Drawing Squares and Circles in JavaFX”

Open and Save Menus in JavaFX

I have already written a tutorial on JavaFX FileChoosers. However, the previous example did not integrate a JavaFX MenuBar or an FXML file into the mix. Typically, you don’t create or design FileChoosers in FXML, though some dialogs can be designed in FXML. However, FileChoosers tend to be created and shown programmatically, rather than in FXML for display later.

This JavaFX FileChooser example shows a basic MenuBar with Open, Save, SaveAs and Quit MenuItems as shown in the image below.

JavaFX FileChooser Menus
A simple JavaFX MenuBar with Open, Save, Save As and Quit MenuItems.

Continue reading “Open and Save Menus in JavaFX”

JavaFX Documentation

If you’ve been browsing around the standard Javadocs for the Java API’s looking for JavaFX Javadocs, then you’re probably frustrated. Where are those JavaFX Javadocs? JavaFX like any Java API has its own set of Javadocs.

This is the location of the JavaFX 8 Javadocs. JavaFX 8 is large enough that it was deserving of its own Javadoc site.


JavaFX Javadocs
JavaFX is large and complex, so has its own Javadocs outside of standard Java’s Javadocs.

Some readers may be new to JavaFX and Java in general. For anyone that doesn’t know what a Javadoc is, keep reading.

Continue reading “JavaFX Documentation”

JavaFX File Chooser

The newest version of the JavaFX FileChooser uses native FileChoosers to allow the selection of files. This means that the FileChooser is guaranteed to pass Apple Store requirements on having the OS and not the app control file system operations. However, it also means that the look and feel of your app may clash with the look and feel of the JavaFX file chooser, thus providing a degraded user experience. Most would say that is a fair trade off, as customers will already be used to their OS’s file chooser, and custom a JavaFX file chooser might hurt the user experience.

This short JavaFX tutorial goes into the three most common FileChooser uses. They are:

  1. Choosing one file to open
  2. Choosing multiple files to open
  3. Saving to a file

We’ll go into all three uses with examples.

Continue reading “JavaFX File Chooser”

JavaFX Fahrenheit to Celsius Converter in FXML

JavaFX Fahrenheit to Celsius Example
JavaFX Fahrenheit to Celsius example using FXML to layout the Scene on the Stage.

JavaFX is easy once you get the hang of it, but for new programmers that requires plenty of examples. More experienced programmers will find one or two examples are enough to master most of JavaFX, so a lot of web sites only put one or two examples up—enough for experienced programmers, but not nearly enough for newer programmers.

In this post, I present the classic temperature converter example modified to use JavaFX. This example uses basic MVC/MVP design. If you want to see this same JavaFX tutorial written in pure Java, look for my other tutorial on this site. It will be the one mentioning pure Java instead of FXML.

Continue reading “JavaFX Fahrenheit to Celsius Converter in FXML”

Restriction on Required Library

JavaFX is part of Java, so why does it prove so difficult to get JavaFX code to compile in Eclipse? You would think there wouldn’t be an issue, but there often is a compile error, “Access Restriction: blah blah is not accessible due to restriction on required library”.

So painful.

There are essentially three fixes for this JavaFX access restriction error in Eclipse. Continue reading “Restriction on Required Library”

Recognizing Dragged File Types in JavaFX

Dragging files onto nodes in JavaFX is fairly easy. The main trick is making sure you are only accepting the correct file types. There are several approaches to determining file type on the fly, or on the drag over, in our case. However, I recommend just going with the simplest approach.

While you are dealing with the drag over event, get the Dragboard from the event. Then grab the List<File> from the JavaFX DragBoard. At that point it is simple to get the first file’s Path, convert it to a String, and check that it ends with an acceptable file extension.

No. Really. It’s simple.

Here’s the code for checking for a *.txt file being dragged on to a TextArea that is watching drag over events.

void textDragOver(DragEvent event) {
  Dragboard board = event.getDragboard();
  if (board.hasFiles()) {

    List<File> phil = board.getFiles();
    String path = phil

    if (path.endsWith(".txt")) {


Continue reading “Recognizing Dragged File Types in JavaFX”

JavaFX Drop Plain Text Files

JavaFX drag and drop is easy. Modern apps require the ability to drop files when filling content, instead of opening the files in another application, copying the contents to the clipboard and then pasting the clipboard contents into the new app. Make sure to include drop capabilities in your JavaFX apps. It’s a good idea to have fully flushed out drop events included in your JavaFX applications from the start, or you’re likely to lose customers.

This tutorial shows how to include the ability to drag plain text files on to a JavaFX text area and have that JavaFX text area auto-populate with the contents of the files. Plain text files may or may not have the extension of *.txt. Plain text files  are not the same as rich text files that almost always have the extension of *.rtf.

Continue reading “JavaFX Drop Plain Text Files”

Bare Bones JavaFX “Hello World!”

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!”

Continue reading “Bare Bones JavaFX “Hello World!””

JavaFX Image Converter

Sometimes it is easier to grasp the concepts of a language or library such as JavaFX by seeing it in action. I’ve put together a JavaFX image converter application. This JavaFX app allows you to drag GIF’s, JPEG’s, BMP’s, or PNG’s onto the ImageView and then convert them and save them quickly as any of the other formats mentioned above.

JavaFX Image Converter
This JavaFX app allows quick conversion of BMP, GIF, JPG, and PNG files to any of the other formats and saving to your computer.

This JavaFX app is a double-clickable JAR file. That means that if you want to run it from the JAR file, just make sure you have Java installed and double-click the JavaFX JAR named image-converter.jar.

Continue reading “JavaFX Image Converter”

Drawing Squares and Circles in JavaFX in Pure Java

I already gave an example of how to draw Squares and Circles on an FXML-generatated UI. Sometimes, you want to work without taking the time to create an FXML document. So this example delves into doing the same thing without using FXML.

Just drawing squares isn’t extremely exciting, because, … let’s face it, … the only time you want a window with one square and one circle in it, is when you are implementing the Candy Land board game.

Classic Candy Land Board Game
The only time you need just a circle and a square in a window, is when you are implementing a Candy Land game.
By Source (WP:NFCC#4), Fair use, https://en.wikipedia.org/w/index.php?curid=46225642

Continue reading “Drawing Squares and Circles in JavaFX in Pure Java”

JavaFX Drag and Drop Images

If you deal with files in your JavaFX app, then you need to have drag and drop integration. You’ll be amazed at how easy drag-and-drop is in JavaFX.

The following JavaFX image drag-and-drop example only takes three files. You can just copy them into your JavaFX project, and run them if you’d like.

The resulting application allows you to drag an image file onto your window. As the image file moves over the window, it will change in a OS specific way, indicating that you can drop the file onto the open window. Once you drop the image file on to the window, the image will be displayed in the window. Continue reading “JavaFX Drag and Drop Images”