Fix prompt text disappearing after selection

After selecting an option from the combobox, it would no longer
display the prompt text and instead would be blank.

As per the documentation
https://docs.oracle.com/javase/10/docs/api/javafx/scene/control/ComboBoxBase.html#promptTextProperty:
> Prompt text is not displayed in all circumstances, it is dependent
> upon the subclasses of ComboBoxBase to clarify when promptText will be
> shown.

Therefore, use a custom buttonCell on the combo box to display the
prompt text.
This commit is contained in:
Devin Bileck 2018-10-13 21:43:14 -07:00
parent 313971d7d8
commit 933b0b8277
No known key found for this signature in database
GPG key ID: C86D829C2399D073

View file

@ -426,6 +426,17 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
fiatCurrenciesComboBox = FormBuilder.<FiatCurrency>addLabelComboBox(root, ++gridRow).second;
fiatCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addFiat"));
fiatCurrenciesComboBox.setButtonCell(new ListCell<FiatCurrency>() {
@Override
protected void updateItem(final FiatCurrency item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(Res.get("setting.preferences.addFiat"));
} else {
setText(item.getNameAndCode());
}
}
});
fiatCurrenciesComboBox.setConverter(new StringConverter<FiatCurrency>() {
@Override
public String toString(FiatCurrency tradeCurrency) {
@ -442,6 +453,17 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
cryptoCurrenciesComboBox = labelComboBoxTuple2.second;
GridPane.setColumnIndex(cryptoCurrenciesComboBox, 3);
cryptoCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addAltcoin"));
cryptoCurrenciesComboBox.setButtonCell(new ListCell<CryptoCurrency>() {
@Override
protected void updateItem(final CryptoCurrency item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(Res.get("setting.preferences.addAltcoin"));
} else {
setText(item.getNameAndCode());
}
}
});
cryptoCurrenciesComboBox.setConverter(new StringConverter<CryptoCurrency>() {
@Override
public String toString(CryptoCurrency tradeCurrency) {