Fixed message list dimension

This commit is contained in:
Kai S. K. Engelbart 2020-03-17 12:35:31 +01:00
parent ea75636e7f
commit f10556ac44
2 changed files with 4 additions and 8 deletions

View File

@ -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);

View File

@ -95,7 +95,7 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
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<Message> {
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);