未验证 提交 a5055341 编写于 作者: J Jan S 提交者: GitHub

fix(gui): fix IndexOutOfBoundsException when switching between tabs via mouse...

fix(gui): fix IndexOutOfBoundsException when switching between tabs via mouse wheel (#1456)(PR #1469)
上级 357706b0
......@@ -54,20 +54,26 @@ public class TabbedPane extends JTabbedPane {
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
addMouseWheelListener(e -> {
if (openTabs.isEmpty()) {
addMouseWheelListener(event -> {
int direction = event.getWheelRotation();
if (openTabs.isEmpty() || direction == 0) {
return;
}
int direction = e.getWheelRotation();
direction = (direction < 0) ? -1 : 1; // normalize direction
int index = getSelectedIndex();
int maxIndex = getTabCount() - 1;
if ((index == 0 && direction < 0)
|| (index == maxIndex && direction > 0)) {
index = maxIndex - index;
} else {
index += direction;
index += direction;
// switch between first tab <-> last tab
if (index < 0) {
index = maxIndex;
} else if (index > maxIndex) {
index = 0;
}
try {
setSelectedIndex(index);
} catch (IndexOutOfBoundsException e) {
// ignore error
}
setSelectedIndex(index);
});
interceptTabKey();
enableSwitchingTabs();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册