Skip to content

Commit 488f0d7

Browse files
authored
Merge pull request #11425 from facchinm/scrollable_custommenus
Make Custom menus scrollable
2 parents 57a931c + cb1b845 commit 488f0d7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

app/src/processing/app/Base.java

+1
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ public void actionPerformed(ActionEvent actionevent) {
14731473
customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform));
14741474
customMenu.putClientProperty("removeOnWindowDeactivation", true);
14751475
boardsCustomMenus.add(customMenu);
1476+
MenuScroller.setScrollerFor(customMenu);
14761477
}
14771478
}
14781479
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.awt.event.MouseWheelEvent;
1717
import java.awt.event.MouseWheelListener;
1818
import java.awt.event.KeyEvent;
19+
import java.util.Arrays;
1920

2021
/**
2122
* A class that provides scrolling capabilities to a long menu dropdown or
@@ -33,6 +34,7 @@ public class MenuScroller {
3334

3435
private JPopupMenu menu;
3536
private Component[] menuItems;
37+
private Component[] allMenuItems;
3638
private MenuScrollItem upItem;
3739
private MenuScrollItem downItem;
3840
private final MenuScrollListener menuListener = new MenuScrollListener();
@@ -539,7 +541,8 @@ public void popupMenuCanceled(PopupMenuEvent e) {
539541
}
540542

541543
private void setMenuItems() {
542-
menuItems = menu.getComponents();
544+
allMenuItems = menu.getComponents();
545+
menuItems = Arrays.stream(allMenuItems).filter(x -> x.isVisible()).toArray(Component[]::new);
543546
if (keepVisibleIndex >= topFixedCount
544547
&& keepVisibleIndex <= menuItems.length - bottomFixedCount
545548
&& (keepVisibleIndex > firstIndex + scrollCount
@@ -554,7 +557,7 @@ private void setMenuItems() {
554557

555558
private void restoreMenuItems() {
556559
menu.removeAll();
557-
for (Component component : menuItems) {
560+
for (Component component : allMenuItems) {
558561
menu.add(component);
559562
}
560563
}

0 commit comments

Comments
 (0)