So I am new to Java FX and I have a textfield element which I want to disable editing on. I can't change it to just text as I need a field later on. Besides, I really want to find out why this is happening.
This is how my constructor and variable declaration looks like:
@FXML
private TextField display;
public Controller(){
display.setEditable(false);
display.setMouseTransparent(true);
display.setFocusTraversable(false);
}
This is my FXML:
<TextField fx:id="display" id="displayCSS"></TextField>
Everytime I launch the application, I get a nullpointer exception beacuse I can't use any methods on a null object. Fine. So I moved the constructor code to a clicklistener for another button and that worked just fine. So I can use the display reference any time I want, except in the constructor. Is there something about constructors and Java fx that I don't understand? Why is this happening?