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

JavaFX Material Design Hamburgers and Transitions


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.

1. 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 is triggered  using play() method. The state of the transition ( either arrow or hamburger) is toggled via setRate() method.

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 is set to -1 which is the hamburger. When the user clicks on the hamburger, it is then changed 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.

2. HamburgerBasicCloseTransition 

This Transition Converts the hamburger to a close form. Usage of this one is very similar to the above except the class used.


HamburgerBasicCloseTransition transition = new HamburgerBasicCloseTransition(hamburger);
3. HamburgerSlideCloseTransition 

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

HamburgerSlideCloseTransition transition = new HamburgerSlideCloseTransition(hamburger);
4.HamburgerNextArrowBasicTransition

This transition converts the hamburger to a forward arrow.

HamburgerNextArrowBasicTransition transition = new HamburgerNextArrowBasicTransition(hamburger);


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

Share the post

JavaFX Material Design Hamburgers and Transitions

×

Subscribe to The Genuine Coder

Get updates delivered right to your inbox!

Thank you for your subscription

×