Reputation: 43
I'm using a JFoenix library and I have a problem with ComboBox.
When I want to setPromtText and setButtonCell - the text duplicates. I want to change the size of font on ButtonCell.
Here is my code:
@FXML
private JFXComboBox versionList;
@Override
public void initialize(URL location, ResourceBundle resources) {
versionList.setPromptText("<");
versionList.setButtonCell(new ListCell<String>() {
@Override
protected void updateItem(String version, boolean empty) {
if (empty) {
setText(null);
} else {
setText(version);
setFont(Font.font(15));
}
}
});
}
And as the result I get this:
Or if promt text "Select":
What I'm doing wrong? Thanks in advance.
Upvotes: 0
Views: 167
Reputation: 209330
You have omitted to call the superclass implementation of updateItem(...)
in your overridden updateItem(...)
method. According to the documentation this will prevent the item
and empty
properties from being set; so I suspect that what is happening is that the cell still has empty==true
, and consequently draws the prompt text when it shouldn't.
The correct implementation should be
@Override
public void initialize(URL location, ResourceBundle resources) {
versionList.setPromptText("<");
versionList.setButtonCell(new ListCell<String>() {
@Override
protected void updateItem(String version, boolean empty) {
super.updateItem(version, empty);
if (empty) {
setText(null);
} else {
setText(version);
setFont(Font.font(15));
}
}
});
}
Upvotes: 1