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 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import java.awt.Component;
|
|||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -77,6 +78,9 @@ public final class ChatPanel extends JPanel {
|
|||||||
|
|
||||||
tabs.setFont(Theme.uiFont());
|
tabs.setFont(Theme.uiFont());
|
||||||
tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
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(serverTab, false);
|
||||||
addTab(channelTab, false);
|
addTab(channelTab, false);
|
||||||
tabs.setSelectedIndex(0);
|
tabs.setSelectedIndex(0);
|
||||||
@@ -346,10 +350,11 @@ public final class ChatPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component header(boolean closable) {
|
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);
|
p.setOpaque(false);
|
||||||
titleLabel = new JLabel(title, icon, JLabel.LEADING);
|
titleLabel = new JLabel(title, icon, JLabel.LEADING);
|
||||||
titleLabel.setFont(Theme.uiFont());
|
titleLabel.setFont(Theme.uiFont());
|
||||||
|
titleLabel.setIconTextGap(3);
|
||||||
p.add(titleLabel);
|
p.add(titleLabel);
|
||||||
dragReorder.attach(p);
|
dragReorder.attach(p);
|
||||||
dragReorder.attach(titleLabel);
|
dragReorder.attach(titleLabel);
|
||||||
@@ -367,13 +372,6 @@ public final class ChatPanel extends JPanel {
|
|||||||
});
|
});
|
||||||
p.add(close);
|
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));
|
p.setPreferredSize(new Dimension(p.getPreferredSize().width, 20));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ final class TabDragReorder {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
if (dragging) endDrag();
|
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;
|
pressSlot = -1;
|
||||||
dragging = false;
|
dragging = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user