Fixed spacing in ComponentList

This commit is contained in:
Kai S. K. Engelbart 2020-02-01 11:34:57 +01:00
parent 2436afc8e9
commit 689b8bdf8d
2 changed files with 17 additions and 6 deletions

View File

@ -166,14 +166,17 @@ public class ChatWindow extends JFrame {
final JList<User> selectedUserList = (JList<User>) 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);

View File

@ -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<E> extends JPanel {
*/
public void setModel(ComponentListModel<E> 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<E> 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<E> extends JPanel {
void synchronizeModel() {
removeAll();
if (model != null) for (E elem : model)
add(renderer.getListCellComponent(this, elem, false));
add(elem);
}
}