Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 984
David Avatar asked Sep 08 '15 07:09

David


People also ask

How do I remove a label in JavaFX?

If you want to erase the content of the label, do: final Label result = ... root. add(result, 0, 1); button.

How do you set a hidden label in JavaFX?

Making Labels Invisible You can set the value to this property using the setLabelsVisible() method. To make the labels of the current pie chart invisible you need to invoke this method by passing the boolean value false as a parameter.

How do I hide TextField?

The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted.

How do you make a TextField not editable in JavaFX?

In FXML, add editable="false" to your TextField tag. Or uncheck the "Editable" checkbox in Scene Builder.


2 Answers

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

To Hide :- You need to set the visible property to false.

The possible reason's why its not working in your case is that if you have skipped mentioning the fx:id for your TextField or Label.

To do so just go through the fxml if using and set the fx:id="myTextField" , and then the same code that you have write will start to work.

The same is used to hide any Label.

To Deactivate :- There is a field named as disable just set that disable property to true to disable or deactivate any field.

like image 68
Chetan Hallan Avatar answered Oct 05 '22 04:10

Chetan Hallan


I understand that you want to hide/show a text field (javaFX), i usually use the same method you mentioned assume that the text field variable name is field then:

to hide it use

field.setVisible(false);

to show it use

field.setVisible(true);

and it works always for me.

like image 39
Hossein ElDelbani Avatar answered Oct 05 '22 04:10

Hossein ElDelbani