IntelliJ feature? Automatically generate fx:id fields in controller class
已回答
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?
请先登录再写评论。
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
I manually creaed them with the Scene Builder 2.0.
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.
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.
Thank you for your reply! This does seem to solve my issue.