Chika Okereke Chika has written much of the JavaFX converter and also helps with the HTML5 converter. When not experimenting with the new features of JavaFX, he is a keen basketball player (he is the tall guy you might see at Devoxx).

PDF to JavaFX conversion – Creating a JavaFX application using FXML with NetBeans

1 min read

Following on from my previous blog. I will now give a walk through on how to create a simple JavaFX application using FXML (to define the UI) in the NetBeans 7.1 IDE. You will need this to run any converted PDF files or to write new JavaFX using FXML.

Just like creating any project using NetBeans, open up NetBeans click on File>New Project>JavaFx>JavaFx FXML Application.

Give your project a name, in this example I have called mine "JavaFXMLTutorial". Make sure the "Create Application Class" and "Set as Main Project" are both ticked respectively and click on "Finish".

After choosing the name of your project three files get generated JavaFXMLTutorial.java , Sample.java and Sample.fxml. We are going to merge the two java files into one big file to hold both the fxml methods and main method/runnable commands. Open up the JavaFXMLTutorial.java as this is where the application is packaged/built so it would be easier to add the Sample.java content. First of all make the JavaFXMLTutorial.java class implement Initializable, this would automatically make some imports which will then require you to implement all the abstract methods. Only one in this case (initialize) which you can add just below the start method. After which you can delete the Sample.java class.

@Override
public void initialize(URL arg0, ResourceBundle arg1) {

}

Go back to the Sample.fxml file and change the fx:controller from javafxmltutorial.Sample (as it is referring to the Sample.java class which does not exist any more) to javafxmltutorial.JavaFXMLTutorial as we have now moved the Initializable interface into the JavaFXMLTutorial.

fx:controller="javafxmltutorial.Sample";

Like this

fx:controller="javafxmltutorial.JavaFXMLTutorial";

Delete the contents of the <children> node which includes <Button> and <Label>. And replace with this line of code.

<Label text="Hello world" style="-fx-text-fill: rgb(255,32,32)";/>

The end product should be a 200 by 320 white box with the text “Hello world” in red. Over time I will build this program and add Buttons, Images, Hyperlinks, etc. And will also show how to link the fxml file with the java file using fx:id and @FXML annotations.

To add the finishing touches open up the JavaFXMLTutorial.java and insert this snippet of code in the start method. This gives the program a name as shown below. In this case “JavaFXMLTutorial”, it can be anything of your choosing.

stage.setTitle("JavaFXMLTutorial");

These are the foundations of creating a FXML application, stay tuned and there will be a lot more to come in my next blogs. Let me know what you think and what you want to see added?

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Chika Okereke Chika has written much of the JavaFX converter and also helps with the HTML5 converter. When not experimenting with the new features of JavaFX, he is a keen basketball player (he is the tall guy you might see at Devoxx).

Updates on Java PDF Viewer roadmap from IDRsolutions

My previous blog post (5 changes we are considering in 2016 for IDRsolutions), generated lots of feedback for us (for which we would like...
Mark Stephens
58 sec read

My key takeaways from NetBeans Day 2015

NetBeans Day 2015 had to be rescheduled to bigger rooms because of attendee demand. It was a very busy schedule. Here are my notes...
Mark Stephens
2 min read

An Introduction to JavaFX Panes with Code Examples

As a developer at IDR Solutions I spend a lot of my time working with JavaFX and Panes in our JavaFX PDF Viewer. I...
Sylwia Dorota Kedzia
1 min read

2 Replies to “PDF to JavaFX conversion – Creating a JavaFX application…”

  1. There is no such thing as a JavaFXML application. The right terminology is “a JavaFX application using FXML (to define the UI)”

Leave a Reply

Your email address will not be published. Required fields are marked *