Skip to content

Commit

Permalink
fix(gui): fix IndexOutOfBoundsException when switching between tabs v…
Browse files Browse the repository at this point in the history
…ia mouse wheel (#1456)(PR #1469)
  • Loading branch information
jpstotz authored Apr 26, 2022
1 parent 357706b commit a505534
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions jadx-gui/src/main/java/jadx/gui/ui/TabbedPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a505534

Please sign in to comment.