33 */
44package processing .app .tools ;
55
6+ import java .awt .BorderLayout ;
67import java .awt .Color ;
78import java .awt .Component ;
89import java .awt .Dimension ;
910import java .awt .Graphics ;
1011import java .awt .event .ActionEvent ;
1112import java .awt .event .ActionListener ;
13+ import java .awt .event .MouseWheelEvent ;
14+ import java .awt .event .MouseWheelListener ;
15+
1216import javax .swing .Icon ;
1317import javax .swing .JComponent ;
1418import javax .swing .JMenu ;
2024import javax .swing .event .ChangeListener ;
2125import javax .swing .event .PopupMenuEvent ;
2226import javax .swing .event .PopupMenuListener ;
23- import javax .swing .plaf .* ;
27+ import javax .swing .plaf .ButtonUI ;
2428
2529/**
2630 * A class that provides scrolling capabilities to a long menu dropdown or
@@ -42,6 +46,7 @@ public class MenuScroller {
4246 private MenuScrollItem upItem ;
4347 private MenuScrollItem downItem ;
4448 private final MenuScrollListener menuListener = new MenuScrollListener ();
49+ private final MouseScrollListener mouseWheelListener = new MouseScrollListener ();
4550 private int scrollCount ;
4651 private int interval ;
4752 private int topFixedCount ;
@@ -320,6 +325,7 @@ public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
320325
321326 this .menu = menu ;
322327 menu .addPopupMenuListener (menuListener );
328+ menu .addMouseWheelListener (mouseWheelListener );
323329 }
324330
325331 /**
@@ -446,6 +452,7 @@ public void keepVisible(int index) {
446452 public void dispose () {
447453 if (menu != null ) {
448454 menu .removePopupMenuListener (menuListener );
455+ menu .removeMouseWheelListener (mouseWheelListener );
449456 menu = null ;
450457 }
451458 }
@@ -497,6 +504,14 @@ private void refreshMenu() {
497504 }
498505 }
499506
507+ private class MouseScrollListener implements MouseWheelListener {
508+ public void mouseWheelMoved (MouseWheelEvent mwe ) {
509+ firstIndex += mwe .getWheelRotation ();
510+ refreshMenu ();
511+ mwe .consume ();
512+ }
513+ }
514+
500515 private class MenuScrollListener implements PopupMenuListener {
501516
502517 @ Override
@@ -555,6 +570,7 @@ private void restoreMenuItems() {
555570 }
556571 }
557572
573+ @ SuppressWarnings ("serial" )
558574 private class MenuScrollTimer extends Timer {
559575
560576 public MenuScrollTimer (final int increment , int interval ) {
@@ -569,6 +585,7 @@ public void actionPerformed(ActionEvent e) {
569585 }
570586 }
571587
588+ @ SuppressWarnings ("serial" )
572589 private class MenuScrollItem extends JMenuItem
573590 implements ChangeListener {
574591
0 commit comments