From 65f37776732beeeec01dbab9d654b7e9c6546a1f Mon Sep 17 00:00:00 2001 From: ericek111 Date: Thu, 20 Aug 2026 07:27:17 +0000 Subject: [PATCH] Let a chat tab grow to fit its name Its header was pinned to the width it was built with, clipping longer names. Co-Authored-By: Claude Opus 5 --- .../main/java/com/ts3client/ui/ChatPanel.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/ChatPanel.java b/ts3-client/swing/src/main/java/com/ts3client/ui/ChatPanel.java index 7d5c257..1c528ee 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/ChatPanel.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/ChatPanel.java @@ -58,6 +58,9 @@ public final class ChatPanel extends JPanel { private final JTextField input = new JTextField(); private final SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss"); + /** Tab strip height, so a tab with no icon still lines up with the others. */ + private static final int HEADER_HEIGHT = 20; + private static final String NO_SERVER = "Server"; private static final String NO_CHANNEL = "Channel"; @@ -350,7 +353,15 @@ public final class ChatPanel extends JPanel { } Component header(boolean closable) { - JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)); + // Only the height is pinned: a fixed width would freeze the tab at the width of + // whatever name it was built with, clipping longer ones (and the bold unread font). + JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)) { + @Override + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + return new Dimension(d.width, Math.max(d.height, HEADER_HEIGHT)); + } + }; p.setOpaque(false); titleLabel = new JLabel(title, icon, JLabel.LEADING); titleLabel.setFont(Theme.uiFont()); @@ -372,7 +383,6 @@ public final class ChatPanel extends JPanel { }); p.add(close); } - p.setPreferredSize(new Dimension(p.getPreferredSize().width, 20)); return p; } @@ -382,7 +392,11 @@ public final class ChatPanel extends JPanel { this.title = title; int index = tabs.indexOfComponent(scroll); if (index >= 0) tabs.setTitleAt(index, title); - if (titleLabel != null) titleLabel.setText(title); + if (titleLabel == null) return; + titleLabel.setText(title); + // The strip lays its tabs out itself; it has to re-measure this one. + tabs.revalidate(); + tabs.repaint(); } void setUnread(boolean unread) {