From f10556ac440623fc2107514b67390e792878032a Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 17 Mar 2020 12:35:31 +0100 Subject: [PATCH] Fixed message list dimension --- src/main/java/envoy/client/ui/ChatWindow.java | 8 ++------ .../envoy/client/ui/renderer/MessageListRenderer.java | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index c7f74f4..182f824 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -130,15 +130,11 @@ public class ChatWindow extends JFrame { scrollPane.setViewportView(messageList); scrollPane.addComponentListener(new ComponentAdapter() { - // updates list elements when list is resized + // Update list elements when scroll pane (and thus list) is resized @Override public void componentResized(ComponentEvent e) { - var prefSize = e.getComponent().getPreferredSize(); - e.getComponent().setPreferredSize(prefSize); + messageList.setMaximumSize(new Dimension(scrollPane.getWidth(), Integer.MAX_VALUE)); messageList.synchronizeModel(); - messageList.setMinimumSize(new Dimension(prefSize.width, 0)); - messageList.setMaximumSize(new Dimension(prefSize.width, Integer.MAX_VALUE)); - messageList.setPreferredSize(new Dimension(prefSize.width, (int) messageList.getPreferredSize().getHeight())); } }); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); diff --git a/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java b/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java index e6622b4..27a5a0d 100644 --- a/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/renderer/MessageListRenderer.java @@ -95,7 +95,7 @@ public class MessageListRenderer implements ComponentListCellRenderer { messageTextArea.setEditable(false); var font = new Font("Arial", Font.PLAIN, 14); messageTextArea.setFont(font); - messageTextArea.setSize(list.getWidth() - padding - 16, 10); + messageTextArea.setSize(list.getMaximumSize().width - padding - 16, 10); var gbc_messageTextArea = new GridBagConstraints(); gbc_messageTextArea.fill = GridBagConstraints.HORIZONTAL; @@ -129,7 +129,7 @@ public class MessageListRenderer implements ComponentListCellRenderer { panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, ours ? padding : 0, 10, ours ? 0 : padding), BorderFactory.createEtchedBorder())); - var size = new Dimension(list.getWidth(), panel.getPreferredSize().height); + var size = new Dimension(list.getMaximumSize().width - 50, panel.getPreferredSize().height); panel.setPreferredSize(size); panel.setMinimumSize(size);