On this section of my series of JavaFX tutorial, we will be showing on the form creation which is very common in developing a desktop application. We will be showing on how to layout the form, add controls, and events.
Creating a Form in JavaFX
For the rest of all my javafx tutorial, I will be using mostly netbeans thus if you have not installed it yet, please do so. If you have not yet created your first application in JavaFX, it would be better to start in Hello World tutorial first which serves as the foundation in creating more advanced application.
A good example for demonstration is a simple tax calculator. It would have labels, textbox, and button. Pressing the button will calculate the tax and will display the result as a message on the form. Please follow these simple steps
- Create a new JavaFX Project and named it TaxCalculator.
- A TaxCalculator.java will be generated automatically and it will show the hello world template.
- Remove all the codes on the start method
- Now first and foremost set the title of the form “JavaFX Tax Calculator” which will appear at the left top most part of the form
Java1primaryStage.setTitle("JavaFX Tax Calculator");
- And make the stage visible using the command
- The code that we have as this moment would be able to generate the following if you try to run it