diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index da64632..ab9e968 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -166,14 +166,17 @@ public class ChatWindow extends JFrame { final JList selectedUserList = (JList) listSelectionEvent.getSource(); final User user = selectedUserList.getSelectedValue(); + // Select current chat currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get(); - // Set all unread messages in the chat to read + // Read current Chat currentChat.read(); + // Set recipient in client and chat title client.setRecipient(user); textPane.setText(currentChat.getRecipient().getName()); + // Update model and scroll down messageList.setModel(currentChat.getModel()); scrollPane.setChatOpened(true); diff --git a/src/main/java/envoy/client/ui/list/ComponentList.java b/src/main/java/envoy/client/ui/list/ComponentList.java index 47f8c31..5b2ea45 100644 --- a/src/main/java/envoy/client/ui/list/ComponentList.java +++ b/src/main/java/envoy/client/ui/list/ComponentList.java @@ -1,6 +1,9 @@ package envoy.client.ui.list; +import java.awt.Dimension; + import javax.swing.BoxLayout; +import javax.swing.JComponent; import javax.swing.JPanel; /** @@ -57,10 +60,8 @@ public class ComponentList extends JPanel { */ public void setModel(ComponentListModel model) { // Remove old model - if (this.model != null) { - this.model.clear(); + if (this.model != null) this.model.setComponentList(null); - } // Synchronize with new model this.model = model; @@ -75,7 +76,14 @@ public class ComponentList extends JPanel { * @param elem the element to add * @since Envoy v0.3-alpha */ - void add(E elem) { add(renderer.getListCellComponent(this, elem, false)); } + void add(E elem) { + JComponent c = renderer.getListCellComponent(this, elem, false); + Dimension size = new Dimension(getWidth(), 50); + c.setMaximumSize(size); + c.setMinimumSize(size); + c.setPreferredSize(size); + add(c); + } /** * Removes all child components and then adds all components representing the @@ -86,6 +94,6 @@ public class ComponentList extends JPanel { void synchronizeModel() { removeAll(); if (model != null) for (E elem : model) - add(renderer.getListCellComponent(this, elem, false)); + add(elem); } }