I just started transitioning from Swing to JavaFX (forever) and i've gotten pretty good so far! I have managed to populate a ComboBox from a list of entities and adding a blank item on top of the list, like such :
supplierSearch = new ComboBox();
ObservableList<Supplier> suppliers = FXCollections.observableArrayList(supplierService.findAll());
suppliers.add(0, new Supplier());
supplierSearch.setItems(suppliers);
supplierSearch.setPromptText("Recherche Fournisseur");
supplierSearch.setMaxWidth(Double.MAX_VALUE);
supplierSearch.getSelectionModel().selectedItemProperty().addListener((observable) ->
{
filterProducts();
});
One thing that bothers me is that the prompt text never comes back when selecting the blank item, it is only there when the ComboBox is initially created and as soon as you click an item (or the blank line in the first position) it never reappears. Is there a way to show the prompt text back when selecting the blank item?
Thanks!