From 9101542f0abf94f05fef99e4375bbfd72904689f Mon Sep 17 00:00:00 2001 From: ericek111 Date: Thu, 20 Aug 2026 07:04:26 +0000 Subject: [PATCH] Switch chat tabs by clicking them, and tighten their padding A custom tab component swallows the press, so the tabbed pane never selected the tab itself; the reorder listener already on every tab part now does it. Co-Authored-By: Claude Opus 5 --- .../src/main/java/com/ts3client/ui/ChatPanel.java | 14 ++++++-------- .../main/java/com/ts3client/ui/TabDragReorder.java | 6 ++++++ 2 files changed, 12 insertions(+), 8 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 d05ac0d..7d5c257 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 @@ -20,6 +20,7 @@ import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.Insets; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -77,6 +78,9 @@ public final class ChatPanel extends JPanel { tabs.setFont(Theme.uiFont()); tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); + // Half the look and feel's leading padding: these tabs carry a name that is worth + // the width, and their headers bring their own spacing. + tabs.putClientProperty("JTabbedPane.tabInsets", new Insets(4, 6, 4, 12)); addTab(serverTab, false); addTab(channelTab, false); tabs.setSelectedIndex(0); @@ -346,10 +350,11 @@ public final class ChatPanel extends JPanel { } Component header(boolean closable) { - JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 0)); + JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)); p.setOpaque(false); titleLabel = new JLabel(title, icon, JLabel.LEADING); titleLabel.setFont(Theme.uiFont()); + titleLabel.setIconTextGap(3); p.add(titleLabel); dragReorder.attach(p); dragReorder.attach(titleLabel); @@ -367,13 +372,6 @@ public final class ChatPanel extends JPanel { }); p.add(close); } - // Clicking the header itself must still switch tabs. - p.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - tabs.setSelectedComponent(scroll); - } - }); p.setPreferredSize(new Dimension(p.getPreferredSize().width, 20)); return p; } diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/TabDragReorder.java b/ts3-client/swing/src/main/java/com/ts3client/ui/TabDragReorder.java index 3fc2fdc..55f475a 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/TabDragReorder.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/TabDragReorder.java @@ -89,6 +89,12 @@ final class TabDragReorder { @Override public void mouseReleased(MouseEvent e) { if (dragging) endDrag(); + // A custom tab component swallows the press, so the tabbed pane never gets + // to select the tab itself — a plain click has to do it here. + else if (pressSlot >= 0 && pressSlot < tabbed.getTabCount() + && SwingUtilities.isLeftMouseButton(e)) { + tabbed.setSelectedIndex(pressSlot); + } pressSlot = -1; dragging = false; }