userListModel = new DefaultListModel<>();
+ users.getUser().forEach(user -> userListModel.addElement(user));
+ SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
+ }).start();
}
/**
@@ -225,9 +202,9 @@ public class ChatWindow extends JFrame {
* @param message The message to append
*/
private void appendMessageToChat(Message message) {
- listModel.addElement("" + " " + message.getMetaData().getSender()
- + " " + "
" + "
" + getFirstTextContent(message)
- + "");
+ messageListModel.addElement("" + "
"
+ + message.getMetaData().getSender() + " " + "
" + "
"
+ + getFirstTextContent(message) + "");
}
public static void main(String[] args)
diff --git a/src/main/java/envoy/client/ui/UserJListModel.java b/src/main/java/envoy/client/ui/UserJListModel.java
deleted file mode 100644
index 05473e9..0000000
--- a/src/main/java/envoy/client/ui/UserJListModel.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package envoy.client.ui;
-
-import java.util.*;
-import java.util.LinkedList;
-
-import javax.swing.AbstractListModel;
-
-import envoy.client.EnvoyClient;
-import envoy.schema.User;
-import envoy.schema.Users;
-
-public class UserJListModel extends AbstractListModel {
-
- public EnvoyClient envoyClient = new EnvoyClient();
- Users users = envoyClient.getUsersListXml();
- private List userList = new LinkedList<>();
-
- public UserJListModel() {
- users.getUser().forEach(user -> userList.add(user));
- }
-
-
- @Override
- public int getSize() {
- return userList.size();
- }
-
- @Override
- public Object getElementAt(int index) {
- return userList.get(index).getName();
- }
-
- public long getElementID(int index) {
- return userList.get(index).getID();
- }
-
-
-}
diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/UserListRenderer.java
new file mode 100644
index 0000000..3c62e48
--- /dev/null
+++ b/src/main/java/envoy/client/ui/UserListRenderer.java
@@ -0,0 +1,41 @@
+package envoy.client.ui;
+
+import java.awt.Component;
+
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+import envoy.schema.User;
+
+/**
+ * Project: envoy-client
+ * File: UserListRenderer.java
+ * Created: 12 Oct 2019
+ *
+ * @author Kai S. K. Engelbart
+ */
+public class UserListRenderer extends JLabel implements ListCellRenderer {
+
+ private static final long serialVersionUID = 5164417379767181198L;
+
+ @Override
+ public Component getListCellRendererComponent(JList extends User> list, User value, int index, boolean isSelected,
+ boolean cellHasFocus) {
+ if (isSelected) {
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
+ } else {
+ setBackground(list.getBackground());
+ setForeground(list.getForeground());
+ }
+
+ // Enable background rendering
+ setOpaque(true);
+
+ setText(value.getName());
+ setFont(list.getFont());
+
+ return this;
+ }
+}