I have a situation where a context menu can potentially have hundreds of menu items added to it. By default a context menu will show scroll buttons at the top/bottom of the popup, but it takes the full height of the screen. I tried setting the maxHeight and prefHeight values, but this had no effect.
Ideally I would like to show a scroll bar instead of scroll buttons at the top and bottom (ie put it in a scroll pane).
Here is a snippet of the code that I am currently have:
ContextMenu menu = new ContextMenu();
menu.setMaxHeight(500);
menu.setPrefHeight(500);
for(TabFX<T> tab : overflowTabs) {
MenuItem item = new MenuItem(tab.getTabName());
if (tab.getGraphic() != null) item.setGraphic(tab.getGraphic());
item.setOnAction(e -> {
select(tab);
layoutTabs();
});
menu.getItems().add(item);
}
Point2D p = overflowBtn.localToScreen(0, overflowBtn.getHeight());
menu.show(overflowBtn, p.getX(), p.getY());
Is there a workaround for this?