IntelliJ feature? Automatically generate fx:id fields in controller class

Answered

I have my FXML with some nodes that have their fx:id's.
Is there any way in IntelliJ to create all the fields (linked to these fx:id's) in the controller class of my fxml-file?

5 comments
Comment actions Permalink

Unfortunately only Alt-Enter|Create field intention is available. How did you get fxml with lots of ids? Were they created manually or was the fxml generated?

Thanks,
Anna

0
Comment actions Permalink

I manually creaed them with the Scene Builder 2.0.

0
Comment actions Permalink

I've noticed this feature automatically creates a public field without the @FXML annotation. It would be much more useful if the field would be generated with the @FXML annotation, and with private access modifier, as these are the conventions when writing JavaFX controllers.   

 

Thanks. 

0
Comment actions Permalink

It's possible to get private fields annotated with @FXML by changing the generated field visibility settings.

It's here: File | Settings | Editor | Code Style | Java | Code Generation | Default Visibility - choose Escalate or Private. Escalate means use minimal valid visibility, which is private for fx:id but is more flexible in other cases.

Also, you may quickly find this by tying 'default visibility' in the Settings dialog's search field.

2
Comment actions Permalink

Thank you for your reply! This does seem to solve my issue.

0

Please sign in to leave a comment.