How to Create JavaFX slider navigation and button hover effect

The video tutorial titled “How to Create JavaFX Slider Navigation and Button Hover Effect” demonstrates how to implement interactive and visually appealing elements using JavaFX, a popular framework for building desktop applications with Java. In this tutorial, you will learn how to create a slider navigation component, allowing users to navigate through different sections or screens of the application. Additionally, you will discover how to incorporate hover effects for buttons, enhancing the user experience and providing visual feedback when interacting with the buttons. By following along with this tutorial, you will gain valuable insights into JavaFX’s capabilities for creating dynamic and engaging user interfaces, empowering you to develop more interactive and intuitive applications.

code


package javafx.scheduler;

import com.jfoenix.controls.JFXButton;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.animation.TranslateTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
 *
 * @author Lenovo
 */
public class MainController implements Initializable {
    
    @FXML
    private BorderPane root;
    @FXML
    private VBox vbox_per;
    @FXML
    private TabPane vbox_task;
    @FXML
    private JFXButton Menu;
    @FXML
    private JFXButton MenuClose;
    @FXML
    private VBox slider;
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        slider.setTranslateX(-290);
       Menu.setOnMouseClicked(event->{
           TranslateTransition slide = new TranslateTransition();
           slide.setDuration(Duration.seconds(0.5));
           slide.setNode(slider);
           slide.setToX(0);
           slide.play();
           slider.setTranslateX(-290);
           slide.setOnFinished((ActionEvent e)->{
               Menu.setVisible(false);
               MenuClose.setVisible(true);
           });
       });
       
    
         MenuClose.setOnMouseClicked(event->{
           TranslateTransition slide = new TranslateTransition();
           slide.setDuration(Duration.seconds(0.5));
           slide.setNode(slider);
           slide.setToX(-290);
           slide.play();
           slider.setTranslateX(0);
           slide.setOnFinished((ActionEvent e)->{
               Menu.setVisible(true);
               MenuClose.setVisible(false);
           });
       });
      
    }
}

Leave a Reply