minuit

ContextMenuComponent

A right-click menu with icons, shortcuts, checks and submenus.

Java

Inside a PanelComponent constructor. The same call draws in every family and chroma.

Java
// Last, so that it is drawn on top and offered every input first.
ContextMenuComponent menu = add(new ContextMenuComponent(bounds(), this)
        .on(files)
        .itemsAt((x, y) -> List.of(
                Item.title(files.rowAt(x, y).getName()),
                Item.action("Open", this::open).icon(Icon.FOLDER).shortcut("Enter"),
                Item.separator(),
                Item.check("Show hidden", hidden, on -> hidden = on),
                Item.submenu("Sort by", Item.action("Name", this::byName), Item.action("Date", this::byDate)),
                Item.action("Delete", this::delete).icon(Icon.TRASH))));
// Greys "Delete" for as long as there is nothing to delete; the tip says why.
menu.disabled("Delete", !canDelete, "Nothing selected");

Menu

ContextMenuComponent, menu