Fixed message list dimension
This commit is contained in:
parent
5b6f6bf058
commit
1e11948e10
@ -130,15 +130,11 @@ public class ChatWindow extends JFrame {
|
|||||||
scrollPane.setViewportView(messageList);
|
scrollPane.setViewportView(messageList);
|
||||||
scrollPane.addComponentListener(new ComponentAdapter() {
|
scrollPane.addComponentListener(new ComponentAdapter() {
|
||||||
|
|
||||||
// updates list elements when list is resized
|
// Update list elements when scroll pane (and thus list) is resized
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
var prefSize = e.getComponent().getPreferredSize();
|
messageList.setMaximumSize(new Dimension(scrollPane.getWidth(), Integer.MAX_VALUE));
|
||||||
e.getComponent().setPreferredSize(prefSize);
|
|
||||||
messageList.synchronizeModel();
|
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);
|
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
@ -95,7 +95,7 @@ public class MessageListRenderer implements ComponentListCellRenderer<Message> {
|
|||||||
messageTextArea.setEditable(false);
|
messageTextArea.setEditable(false);
|
||||||
var font = new Font("Arial", Font.PLAIN, 14);
|
var font = new Font("Arial", Font.PLAIN, 14);
|
||||||
messageTextArea.setFont(font);
|
messageTextArea.setFont(font);
|
||||||
messageTextArea.setSize(list.getWidth() - padding - 16, 10);
|
messageTextArea.setSize(list.getMaximumSize().width - padding - 16, 10);
|
||||||
|
|
||||||
var gbc_messageTextArea = new GridBagConstraints();
|
var gbc_messageTextArea = new GridBagConstraints();
|
||||||
gbc_messageTextArea.fill = GridBagConstraints.HORIZONTAL;
|
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),
|
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, ours ? padding : 0, 10, ours ? 0 : padding),
|
||||||
BorderFactory.createEtchedBorder()));
|
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.setPreferredSize(size);
|
||||||
panel.setMinimumSize(size);
|
panel.setMinimumSize(size);
|
||||||
|
Reference in New Issue
Block a user