NavigationView
Sidebar navigation with collapsible categories of selectable items and a full-width accent selection.
Overview
NavigationView is a TreeView specialised for gallery-style left menus. Add groups with addCategory, add pages with NavigationCategory.addItem, and react with onItemSelected. A category header only expands or collapses its group and never clears the selected item. Item ids are unique across the view and can be selected from code with selectItem.
Gallery sidebar
NavigationView nav = new NavigationView();
nav.addCategory("Basic Input").addItem("slider", "Slider");
nav.onItemSelected(item -> open(item.id()));
Related links
- TreeView: Hierarchical tree container rendering collapsable nodes with custom icons, inline editing, and selection.
API
API
| Method | Description |
|---|---|
NavigationView() |
Creates an empty sidebar navigation view. |
NavigationView()
Create a navigation view
Creates an empty sidebar navigation view.
Categories
| Method | Description |
|---|---|
addCategory(String) |
Appends a category in the expanded state. |
addCategory(String, boolean) |
Appends a category and controls whether its items are initially visible. |
categories() |
Returns categories in insertion order. |
clear() |
Removes every category and item. |
NavigationView::addCategory(String)
Add a category
Appends a category in the expanded state.
| Parameter | Type | Description |
|---|---|---|
title |
String |
Visible category header text. |
Returns NavigationCategory: The newly created category, used to add navigation items..
NavigationView::addCategory(String, boolean)
Add a category with initial state
Appends a category and controls whether its items are initially visible.
| Parameter | Type | Description |
|---|---|---|
title |
String |
Visible category header text. |
expanded |
boolean |
True to show the category items initially; false to collapse the category. |
Returns NavigationCategory: The newly created category..
NavigationView::categories()
Get categories
Returns categories in insertion order.
Returns List: An unmodifiable list of categories in insertion order..
NavigationView::clear()
Clear navigation
Removes every category and item.
Returns NavigationView: This view, for fluent configuration..
Items and selection
| Method | Description |
|---|---|
items() |
Returns all items in category and insertion order. |
item(String) |
Looks up an item by its id. |
selectedItem() |
Returns the currently selected item, if any. |
selectItem(String) |
Selects an enabled item by id and expands its category if needed. |
onItemSelected(Consumer) |
Registers a callback invoked when an item is selected. |
NavigationView::items()
Get items
Returns all items in category and insertion order.
Returns List: An immutable snapshot of all items in insertion order..
NavigationView::item(String)
Find an item
Looks up an item by its id.
| Parameter | Type | Description |
|---|---|---|
id |
String |
Item id; null returns null. |
Returns NavigationItem: The matching item, or null when the id is null or unknown..
NavigationView::selectedItem()
Get selected item
Returns the currently selected item, if any.
Returns NavigationItem: The selected item, or null when there is no selection..
NavigationView::selectItem(String)
Select an item
Selects an enabled item by id and expands its category if needed.
| Parameter | Type | Description |
|---|---|---|
id |
String |
Id of an item in this view; unknown or null ids are ignored. |
Returns NavigationView: This view, for fluent configuration..
NavigationView::onItemSelected(Consumer)
Listen for item selection
Registers a callback invoked when an item is selected.
| Parameter | Type | Description |
|---|---|---|
listener |
Consumer |
Callback receiving the selected item; null is accepted and ignored. |
Returns EventSubscription: A subscription that can be cancelled with unsubscribe()..
Appearance
| Method | Description |
|---|---|
categoryColor() |
Returns the mutable background color used for category headers. |
categoryColor(ColorView) |
Sets the category header background color and invalidates the view visually. |
categoryTextColor() |
Returns the mutable text color used for category headers. |
categoryTextColor(ColorView) |
Sets the category header text color and refreshes category rows. |
NavigationView::categoryColor()
Get category background color
Returns the mutable background color used for category headers.
Returns MutableColor: The mutable RGBA category header background color; components are in [0, 1]..
NavigationView::categoryColor(ColorView)
Set category background color
Sets the category header background color and invalidates the view visually.
| Parameter | Type | Description |
|---|---|---|
color |
ColorView |
Source RGBA color; null is ignored. |
Returns NavigationView: This view, for fluent configuration..
NavigationView::categoryTextColor()
Get category text color
Returns the mutable text color used for category headers.
Returns MutableColor: The mutable RGBA category header text color; components are in [0, 1]..
NavigationView::categoryTextColor(ColorView)
Set category text color
Sets the category header text color and refreshes category rows.
| Parameter | Type | Description |
|---|---|---|
color |
ColorView |
Source RGBA color; null is ignored. |
Returns NavigationView: This view, for fluent configuration..