Properly override updateItem method of list cells
This commit is contained in:
parent
8a3ffec859
commit
d14cc47365
@ -28,7 +28,10 @@ public class ContactListCell extends ListCell<Contact> {
|
|||||||
@Override
|
@Override
|
||||||
protected void updateItem(Contact contact, boolean empty) {
|
protected void updateItem(Contact contact, boolean empty) {
|
||||||
super.updateItem(contact, empty);
|
super.updateItem(contact, empty);
|
||||||
if (!empty && contact != null) {
|
if (empty || contact == null) {
|
||||||
|
setText(null);
|
||||||
|
setGraphic(null);
|
||||||
|
} else {
|
||||||
// the infoLabel displays specific contact info, i.e. status of a user or amount
|
// the infoLabel displays specific contact info, i.e. status of a user or amount
|
||||||
// of members in a group
|
// of members in a group
|
||||||
Label infoLabel = null;
|
Label infoLabel = null;
|
||||||
@ -51,7 +54,7 @@ public class ContactListCell extends ListCell<Contact> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
infoLabel.setTextFill(textColor);
|
infoLabel.setTextFill(textColor);
|
||||||
} else
|
} else
|
||||||
// group specific infos
|
// group specific infos
|
||||||
infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members");
|
infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members");
|
||||||
setGraphic(new VBox(new Label(contact.getName()), infoLabel));
|
setGraphic(new VBox(new Label(contact.getName()), infoLabel));
|
||||||
|
@ -45,10 +45,15 @@ public class MessageListCell extends ListCell<Message> {
|
|||||||
@Override
|
@Override
|
||||||
protected void updateItem(Message message, boolean empty) {
|
protected void updateItem(Message message, boolean empty) {
|
||||||
super.updateItem(message, empty);
|
super.updateItem(message, empty);
|
||||||
setGraphic(!empty && message != null ? new HBox(
|
if(empty || message == null) {
|
||||||
|
setText(null);
|
||||||
|
setGraphic(null);
|
||||||
|
} else {
|
||||||
|
setGraphic(new HBox(
|
||||||
new VBox(
|
new VBox(
|
||||||
new Label(dateFormat.format(message.getCreationDate())),
|
new Label(dateFormat.format(message.getCreationDate())),
|
||||||
new Label(message.getText())),
|
new Label(message.getText())),
|
||||||
new Label("", new ImageView(statusImages.get(message.getStatus())))) : null);
|
new Label("", new ImageView(statusImages.get(message.getStatus())))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user