JavaFX Material Design Hamburgers and Transitions

Using Hamburgers from JFoenix material design library

0
4399

Hamburgers are great replacement for menu icons. In material design, hamburgers can be used to trigger various navigation components. In this post, i will show how to add hamburgers to your JavaFX application. I have made a thorough tutorial for JFXHamburger transition.

JFoenix library provides (Read about setting up material design library for JavaFX) JFXHamburger class for implementing Hamburger. It can be dragged and dropped  using Scene Builder as you can see from above video.

JFXHamburger without transition support is merely a 3 parallel lines. But when you associate it with some cool transition, it will become awesome. So let’s have a look in to the transitions.

HamburgerBackArrowBasicTransition1. HamburgerBackArrowBasicTransition

This transition creates a back arrow from the 3 parrallel lines (Hamburger). This can be created by passing the created Hamburger object as parameter to the HamburgerBackArrowBasicTransition class.

HamburgerBackArrowBasicTransition transition = new HamburgerBackArrowBasicTransition(hamburger);
The animation can be started using play() method. The state of the transition ( either arrow or hamburger) is set through setRate() method. The animation is controlled by changing the rate between -1 and 1.
transition.setRate(-1);
hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED,(e)->{
        transition.setRate(transition.getRate()*-1);
        transition.play();
});
As you can see, at first the trasition rate should be set to -1 which is the hamburger. After the user clicks on the hamburger, it is can be updated by multiplying with -1, ie to 1. Now the Hamburger will turn into a arrow. For further clicks on the hamburger, it will iterate  between -1 and 1.

HamburgerBasicCloseTransition2. HamburgerBasicCloseTransition

This transition converts the hamburger to a cross form. Usage of this one is very similar to the above except the class used.

HamburgerBasicCloseTransition transition = new HamburgerBasicCloseTransition(hamburger);

 

3. HamburgerSlideCloseTransitionHamburgerBasicCloseTransition

This transition converts the hamburger to a close form like before, with a cool transition.

HamburgerSlideCloseTransition transition = new HamburgerSlideCloseTransition(hamburger);

 

HamburgerBasicCloseTransition

4.HamburgerNextArrowBasicTransition

This transition converts the hamburger to a forward arrow.

HamburgerNextArrowBasicTransition transition = new HamburgerNextArrowBasicTransition(hamburger);

 

Watch this tutorial in action from Genuine coder YouTube channel

SHARE

Friends call me Villan (Yeah, that’s my name). I am from Kerala, India. Studied Computer Science and Engineering. Love programming and spends free time on experimenting with new programming languages and things. Happy blogger and YouTuber.