Overview
JSidebar is a vertical navigation component that extends JavaFX’s VBox. It supports collapsible states, multiple visual variants, custom header/footer sections, and smooth animations.
Enumerations
CollapseMode
Icons only - sidebar collapses to show only icons (width: 70px)
Completely hidden - sidebar collapses to zero width
SidebarVariant
Dark/standard variant with default styling
Light variant with white background and borders
Constructor
Creates a new sidebar with default settings (expanded, COMPACT mode, DEFAULT variant).
Methods
Items Management
Returns the observable list of sidebar items.
Expand/Collapse
Checks if the sidebar is currently expanded.
Sets the expanded/collapsed state with animation.
Property for the expanded state.
Collapse Mode
Gets the current collapse mode.
Sets the collapse behavior.
Property for the collapse mode.
Variant
Sets the visual variant of the sidebar.
Header and Footer
Sets a custom header node. When set, the toggle button is hidden.
Sets a custom footer node at the bottom of the sidebar.
Related Components
- JSidebarItem - Individual navigation items for the sidebar
Style Classes
Base style class applied to the sidebar container
Applied when using DEFAULT variant
Applied when using LIGHT variant
Applied to the custom header content wrapper
Applied to the top bar containing the toggle button
Applied to the hamburger menu toggle button
Applied to the items container
Applied to the scroll pane wrapping the items
Applied to the footer container
Applied when the sidebar is collapsed
Applied when using COMPACT collapse mode
Applied when using HIDDEN collapse mode
Example Usage
Behavior Notes
- Collapse mode is automatically set based on item icons:
- If any
JSidebarItemhas an icon, mode defaults to COMPACT - If no items have icons, mode defaults to HIDDEN
- If any
- Animations run for 300ms when expanding/collapsing
- Default widths:
- Expanded: 250px
- Compact: 70px
- Hidden: 0px
- The toggle button uses a hamburger menu icon from
JIcon.MENU - When a custom header is set, the default toggle button is hidden
- Items are scrollable if they exceed the available height
Dependencies
- JSidebarItem - Individual sidebar items
- JIcon - Icons for toggle button and items
Source
com.jjarroyo.components.JSidebar in JSidebar.java:23
JSidebarItem
Overview
JSidebarItem is a navigation item component for use within JSidebar. It extends JavaFX’s HBox and displays an icon, label, and supports an active state.
Constructor
Creates a sidebar item with text only.
Creates a sidebar item with text and icon.
Methods
Sets the action to execute when the item is clicked.
Sets the active state of the item.
Checks if the item is currently active.
Property for the active state.
Sets or updates the item icon.
Gets the current icon.
Gets the item text.
Style Classes
Base style class applied to the item container
Applied to the text label
Applied when the item is in active state
Example Usage
Behavior Notes
- Items are clickable and trigger the action on mouse click
- Active state adds the “active” CSS class for visual highlighting
- Icons and labels are horizontally aligned with 12px spacing
- A spacer region is added for future badge support on the right side
Source
com.jjarroyo.components.JSidebarItem in JSidebarItem.java:11