JavaFX how to show read-only text?

I want to show text in my program, and I tried with TextArea . However, the displayed text is mutable. How can I make read-only text?

+9
javafx
source share
6 answers

Maybe just text will serve the purpose.

Or if you want to show text in a text field, then:

 tf.setDisable(true) 
+12
source share

I did it like this:

 @FXML private TextArea myText; 

and then added the following code for initialise() :

 myText.setEditable(false); 
+33
source share

I need read-only text fields, but setting the property to disabled used a style that was incorrect in the context (in my script, the text field was entered into the search function, where the value could be fixed in some cases - disabling the text field implies that it was not part of search, but was not fixed).

I ended up landing using:

 txtInput.setEditable(false); txtInput.setMouseTransparent(true); txtInput.setFocusTraversable(false); 

The result is a normal text field that does not respond to the user.

+21
source share

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

+7
source share

I would say just use Label .

+5
source share
 <TextField fx:id="input" disable="true"/> 
+3
source share

All Articles