AwesomeGuy
AwesomeGuy

Reputation: 547

JavaFX combobox set PromptText after selection option

I've set a prompt text for my combobox which appears before selecting an option.

After the user selects an element in the ComboBox I want that text to appear again, but I don't want it to be a ComboBox item.

I tried clearing the selection and setting the prompt text again, but no text is appearing, it's empty.

How do I need to do it?

Upvotes: 0

Views: 1408

Answers (2)

AixNPanes
AixNPanes

Reputation: 1260

Apparently, the prompt text has one of two kinds of values if the combobox is not editable depending on whether a list cell is selected. If none is selected, the prompt text is the value of the promptText property. If a cell is selected, the value is the toString() value of the object which is selected.

Even if the cellFactory displays values which are not the toString() of the cell object, the prompttext shows the toString() value. It seems that if the prompttext is not going to show the value from the cellFactory then there should be a method or option to show another value.

Upvotes: 0

Matt
Matt

Reputation: 3187

The javadoc states:

public final void setPromptText(String value)

Sets the value of the property promptText.

Property description:

The ComboBox prompt text to display, or null if no prompt text is displayed. Prompt text is not displayed in all circumstances, it is dependent upon the subclasses of ComboBoxBase to clarify when promptText will be shown. For example, in most cases prompt text will never be shown when a combo box is non-editable (that is, prompt text is only shown when user input is allowed via text input).

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ComboBoxBase.html#setPromptText-java.lang.String-

Upvotes: 0

Related Questions