- Joined
- Nov 26, 2014
- Messages
- 616
- Thread Author
- #1
Before reading any further
JavaFX is the latest GUI framework for Java and will soon replace Swing GUIs. This is a quick tutorial on how to get started with JavaFX.
Start off by downloading and installing SceneBuilder:
http://www.oracle.com/technetwork/java/javase/downloads/sb2download-2177776.html
In your project create a new file:
Name your file (make sure the file type is .fxml):
Open the file in SceneBuilder:
Double click AnchorPane to add a parent Container for all other components to be placed in:
For this tutorial, I'll be adding a Combobox to select what rock to mine, a Label, and a Button.
After adding all your components, add a fx:id for all your components that will require user input (so that means don't assign a fx:id to label):
I set my Combobox to "selectRock" and Button to "btnStart".
Now save your fxml file and you should have a simple JavaFX GUI. Unfortunately, everything else will be handcoded.
Let's create the class that will be responsible for showing the file:
And the main script class:
Now when we run the script, the GUI will show up, but the ComboBox will be empty and the button won't do anything. We need to add a Controller that will be responsible for filling the ComboBox and handling input. Remember the fx:id's we set in SceneBuilder? This is where they come into play.
Finally, we have to set the Controller in the FXMLLoader from the TutorialGui class:
End result:
Thanks for reading. Like this post if you found it helpful.
- You should have intermediate programming experience before attempting JavaFX
- I use Intellij IDEA as my IDE, if you are more familiar with another IDE, use that one, the focus is not on the IDE and a few Google searches should resolve any questions with different IDEs
- You should know the basics of writing scripts with RuneMate before attempting to write a RuneMate script using a JavaFX GUI
JavaFX is the latest GUI framework for Java and will soon replace Swing GUIs. This is a quick tutorial on how to get started with JavaFX.
Start off by downloading and installing SceneBuilder:
http://www.oracle.com/technetwork/java/javase/downloads/sb2download-2177776.html
In your project create a new file:
Name your file (make sure the file type is .fxml):
Open the file in SceneBuilder:
Double click AnchorPane to add a parent Container for all other components to be placed in:
For this tutorial, I'll be adding a Combobox to select what rock to mine, a Label, and a Button.
After adding all your components, add a fx:id for all your components that will require user input (so that means don't assign a fx:id to label):
I set my Combobox to "selectRock" and Button to "btnStart".
Now save your fxml file and you should have a simple JavaFX GUI. Unfortunately, everything else will be handcoded.
Let's create the class that will be responsible for showing the file:
And the main script class:
Now when we run the script, the GUI will show up, but the ComboBox will be empty and the button won't do anything. We need to add a Controller that will be responsible for filling the ComboBox and handling input. Remember the fx:id's we set in SceneBuilder? This is where they come into play.
Finally, we have to set the Controller in the FXMLLoader from the TutorialGui class:
End result:
Thanks for reading. Like this post if you found it helpful.