JavaFX Live Templates for IntelliJ IDEA


A number of the team at Gluon are fans of IntelliJ IDEA (although not all of us – other team members use Eclipse and NetBeans too – which might explain why we have Gluon IDE tooling for all three major IDEs). We are constantly exploring the various corners of IntelliJ IDEA, and this week we really liked finding the support for adding ‘live templates’. We decided to try our hand at defining our own, and we are very pleased with how well they work!

In short, a live template specifies an abbreviation that you may type into your IDE that auto-completes a large chunk of code for you. We have defined live templates for IntelliJ IDEA to create JavaFX properties, including getters, setters, and the property method, and we have done this with support for all property types, and both read-only and read/write properties. This is a huge productivity boost for us, and we hope it might be for you too.

We know that IntelliJ can already create methods from a property (simply via the alt-insert shortcut) when you have specified the property, but there are two problems with this:

  1. You have to firstly define the property
  2. The generated methods do not follow JavaFX best practices – the methods should all be declared as final, but they are not.

For now we have not created a separate page for these live templates, so you can download them simply from here. Once you have the file on your machine, simply do the following to import them into your IntelliJ IDEA install:

  1. Unzip the zip file. This will result in there being a settings.jar file as the only file.
  2. In IntelliJ, click on the ‘File’ menu
  3. Click on ‘Import Settings…’
  4. Find the settings.jar file on your file system
  5. Restart IntelliJ when asked

Once you have done this, from within your editor, you may simply start to type ‘fxprop‘, and if everything goes to plan you should see a popup that lets you choose the type of property you want, and once you press tab (or enter), this code will be generated inside your editor. You can then immediately start typing the property name, and this will automatically update all the method names. Once you’ve done this, all you need to do is import the relevant classes.

Here’s a screenshot of the live templates in action:

intellij-live-templates

We hope that this is as beneficial and productive for you as it is for us!