javajavafxtextfieldfxml

How to hide or deactivate a TextField and a Label with javafx


I would like to hide or deactivate a TextField and its Label in my JavaFX application.

This is what I tried

myTextField.setVisible(false);

, but it's not working

I use Eclipse V4.5.0 on windows 7 with jfx8 V2.0.0


Solution

  • There is a difference between hiding and deactivating a TextField in JavaFX.

    Hiding the field will make it invisible and disabling (or deactivating) it will make it non-editable.

    Hide: Set the visible property to false.

    The possible reason why it's not working in your case is that you have not mentioned the fx:id property for your TextField or Label.

    To fix it, go to the FXML file and set fx:id="myTextField". Thereafter, the code that you have written would work.

    Deactivate: There is a field named disable. Set it to true to disable or deactivate any field.