404cdee6050e2df2e56a1dbe3fc73d41f6f90c96 — swissChili 5 months ago f337f11
Fix bug in message body JTextArea not resizing to proper height.
Used the size of the JList passed to the ListCellRenderer to calculate the proper number of lines,
a more efficient way to do this may be necessary as currently with very large numbers of messages
there are a lot of calculations done per update.
1 files changed, 9 insertions(+), 2 deletions(-)

M client/src/main/java/sh/swisschili/chat/client/MessageCell.java
M client/src/main/java/sh/swisschili/chat/client/MessageCell.java => client/src/main/java/sh/swisschili/chat/client/MessageCell.java +9 -2
@@ 22,6 22,8 @@ import com.github.weisj.darklaf.components.border.DarkBorders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sh.swisschili.chat.util.ChatProtos.Message;

import javax.swing.*;

@@ 37,13 39,18 @@ public class MessageCell implements ListCellRenderer<Message> {
    public MessageCell() {

    public MessageCell(@NotNull Message value) {
    public MessageCell(@NotNull Message value, int parentWidth) {

        int width = parentWidth / 6;
        int lines = value.getBody().length() / width + 1;



        time.setText(new Date(value.getUnixTime()).toString());
        Font f = sender.getFont();

@@ 55,7 62,7 @@ public class MessageCell implements ListCellRenderer<Message> {
    public JComponent getListCellRendererComponent(JList<? extends Message> list, Message value, int index,
                                                   boolean isSelected, boolean cellHasFocus) {
        return new MessageCell(value).rootPanel;
        return new MessageCell(value, list.getWidth()).rootPanel;