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 <noreply@anthropic.com>
This commit is contained in:
2026-08-20 07:27:17 +00:00
parent 9101542f0a
commit 65f3777673

View File

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