I\'m trying to set the button text using this code:
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
/
Why Button Text Does Not Change in Your Program
a. You never associate your controller with your FXML.
Because a controller is never associated with your FXML, a controller is never instantiated and your controller initialization code which sets the button text is never run.
b. You set a CSS id
on your items in FXML rather than an FXML fx:id
.
When you don't set an fx:id
for items in FXML, FXML will not inject references to Java objects for those items into your controller class.
These are very common errors when first starting to write FXML applications. If you wanted, you could write to Oracle at javasedocs_us@oracle.com with a link to this answer and ask Oracle to add an FXML troubleshooting section or common issues section to their documentation.
Associating Controllers with FXML
EITHER:
Use an fx:controller attribute.
In your sample, add an fx:controller attribute to your root node; e.g.
OR
Set a controller in an FXML loader.
Refer to Passing Parameters JavaFX FXML, for info on how to do this.
Setting fx:id
Values
Instead of:
Write: