Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to make Navigation Drawer (Side Panel) in JavaFX

When we want to develop a well designed application, Navigation of the application is very important. Android introduced the material design introduced the Navigation bar or side pane or whatever you call, with its Material design goodness.

Today, I will be showing how to implement the Navigation drawer on your JavaFX application using JFoenix material design library. If you want some help on setting up the JFoenix material design library, see my post JavaFX Material Design : Setting Up and Making Login Application

I have made a video to make things more clear. You can watch it right here.

Let me explain one step at a time.

Navigation Bar Content
Step 1 : Design Content For Navigation Drawer

At first, I have created an FXML layout for the Navigation bar. This layout can then be inflated to the navigation bar holder. This is a pretty simple Vbox layout that consists of 4 Buttons and one image view. This content can the be loaded to a Vbox variable in our code (from the main controller) using the code

VBox box = XMLLoader.load(getClass().getResource("SidePanelContent.fxml")); 

Step 2 : Design The Container (Main) Window
Now we  have the navigation bar content. In this step, we have to design the main application window. The JFXDrawer can be added using scene builder by drag and drop. Once you position the drawer on the space you want, you can set the drawer direction to LEFT, RIGHT, TOP or BOTTOM from the Properties section of Scene Builder.

I have added a JFXHamburger for material design look and feel. I have thouroughly explained how to use JFXHamburger in this video . If you want, you can use a simple button. Add an action listener to your button and add this code

Main Window Design
The navigation drawer can be made visible by using the open() or show() method. It can be made invisible through the function call close().

Step 3 : Setting the content of Drawer
Now in the controller of main scene, we can connect the VBox variable using

Step 4 : You are done !
Run the code now. When you click on your button or Hamburger,you should see the navigation drawer like this. If you have some alignment issues for the drawer, increase the value of "Default Drawer Size" from the Scene Builder.

This post first appeared on The Genuine Coder, please read the originial post: here

Share the post

How to make Navigation Drawer (Side Panel) in JavaFX


Subscribe to The Genuine Coder

Get updates delivered right to your inbox!

Thank you for your subscription