@@ -470,38 +470,46 @@ public void finalize() throws Throwable {
470
470
}
471
471
472
472
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
+ }
476
476
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 );
479
479
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
+ }
484
493
/*if (topFixedCount > 0) {
485
494
menu.addSeparator();
486
495
}*/
487
496
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 );
493
502
494
503
/*if (bottomFixedCount > 0) {
495
504
menu.addSeparator();
496
505
}*/
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 ]);
504
508
}
509
+
510
+ JComponent parent = (JComponent ) upItem .getParent ();
511
+ parent .revalidate ();
512
+ parent .repaint ();
505
513
}
506
514
507
515
private class MouseScrollListener implements MouseWheelListener {
0 commit comments