Skip to content

Commit 4a47eef

Browse files
author
Federico Fissore
committed
Mouse scroll wheel fix for MenuScroller
1 parent 1877703 commit 4a47eef

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

app/src/processing/app/tools/MenuScroller.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -470,38 +470,46 @@ public void finalize() throws Throwable {
470470
}
471471

472472
private void refreshMenu() {
473-
if (menuItems != null && menuItems.length > 0) {
474-
firstIndex = Math.max(topFixedCount, firstIndex);
475-
firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);
473+
if (menuItems == null || menuItems.length == 0) {
474+
return;
475+
}
476476

477-
upItem.setEnabled(firstIndex > topFixedCount);
478-
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
477+
int newFirstIndex = Math.max(topFixedCount, firstIndex);
478+
newFirstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, newFirstIndex);
479479

480-
menu.removeAll();
481-
for (int i = 0; i < topFixedCount; i++) {
482-
menu.add(menuItems[i]);
483-
}
480+
if (newFirstIndex < 0) {
481+
return;
482+
}
483+
484+
firstIndex = newFirstIndex;
485+
486+
upItem.setEnabled(firstIndex > topFixedCount);
487+
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
488+
489+
menu.removeAll();
490+
for (int i = 0; i < topFixedCount; i++) {
491+
menu.add(menuItems[i]);
492+
}
484493
/*if (topFixedCount > 0) {
485494
menu.addSeparator();
486495
}*/
487496

488-
menu.add(upItem);
489-
for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
490-
menu.add(menuItems[i]);
491-
}
492-
menu.add(downItem);
497+
menu.add(upItem);
498+
for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
499+
menu.add(menuItems[i]);
500+
}
501+
menu.add(downItem);
493502

494503
/*if (bottomFixedCount > 0) {
495504
menu.addSeparator();
496505
}*/
497-
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
498-
menu.add(menuItems[i]);
499-
}
500-
501-
JComponent parent = (JComponent) upItem.getParent();
502-
parent.revalidate();
503-
parent.repaint();
506+
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
507+
menu.add(menuItems[i]);
504508
}
509+
510+
JComponent parent = (JComponent) upItem.getParent();
511+
parent.revalidate();
512+
parent.repaint();
505513
}
506514

507515
private class MouseScrollListener implements MouseWheelListener {

0 commit comments

Comments
 (0)