From 9dade2cf77aebb723a7a43db63edcc9129bac3fd Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 10 Jun 2020 11:33:49 +0200 Subject: [PATCH] Properly override updateItem method of list cells --- src/main/java/envoy/client/ui/ContactListCell.java | 7 +++++-- src/main/java/envoy/client/ui/MessageListCell.java | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/client/ui/ContactListCell.java b/src/main/java/envoy/client/ui/ContactListCell.java index c3c51d4..5cb04ca 100644 --- a/src/main/java/envoy/client/ui/ContactListCell.java +++ b/src/main/java/envoy/client/ui/ContactListCell.java @@ -28,7 +28,10 @@ public class ContactListCell extends ListCell { @Override protected void updateItem(Contact contact, boolean 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 // of members in a group Label infoLabel = null; @@ -51,7 +54,7 @@ public class ContactListCell extends ListCell { break; } infoLabel.setTextFill(textColor); - } else + } else // group specific infos infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members"); setGraphic(new VBox(new Label(contact.getName()), infoLabel)); diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index 60a2ada..7b7a479 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -45,10 +45,15 @@ public class MessageListCell extends ListCell { @Override protected void updateItem(Message message, boolean 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 Label(dateFormat.format(message.getCreationDate())), new Label(message.getText())), - new Label("", new ImageView(statusImages.get(message.getStatus())))) : null); + new Label("", new ImageView(statusImages.get(message.getStatus()))))); + } } }