Skip to content

Make Custom menus scrollable #11425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
@@ -1473,6 +1473,7 @@ public void actionPerformed(ActionEvent actionevent) {
customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform));
customMenu.putClientProperty("removeOnWindowDeactivation", true);
boardsCustomMenus.add(customMenu);
MenuScroller.setScrollerFor(customMenu);
}
}
}
7 changes: 5 additions & 2 deletions app/src/processing/app/tools/MenuScroller.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.KeyEvent;
import java.util.Arrays;

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

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

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

private void restoreMenuItems() {
menu.removeAll();
for (Component component : menuItems) {
for (Component component : allMenuItems) {
menu.add(component);
}
}