damat-perdigannat
damat-perdigannat

Reputation: 5950

JavaFX: How do i remove the prompt text in the ComboBox's list?

I have a combo box that has prompt text "Test".
combobox

Say I want to remove the prompt text in the list only like in the image below, how should I do it?
comboboxclear

Thank you.

Upvotes: 0

Views: 1031

Answers (3)

Hek2dl
Hek2dl

Reputation: 1

The simplest way to do this is with this line: Some_ComboBox.getItems().remove(Some_ComboBox.getItems().size()-1);

Upvotes: 0

Hendrik Ebbers
Hendrik Ebbers

Reputation: 2600

I think the best way is to create your custom cellfactory and write a new ListCell class. Here you can add some logic: http://docs.oracle.com/javafx/2/api/javafx/scene/control/ListCell.html

Upvotes: 1

Perneel
Perneel

Reputation: 3367

I guess you can simply do this by using this method:

cbo.setPromptText(null);

http://docs.oracle.com/javafx/2/api/javafx/scene/control/ComboBoxBase.html#setPromptText(java.lang.String)

Upvotes: 0

Related Questions