JavaFX Accordion Example

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.

▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube

▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube

In this JavaFX example, we will see how to use the JavaFX Accordion control with an example.

The JavaFX Accordion control is a container control that can contain several sections internally, each of which can have its content expanded or collapsed. 

The Accordion control is implemented by the JavaFX class javafx.scene.control.Accordion.

JavaFX Accordion Example

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Accordion accordion = new Accordion();
        TitledPane pane1 = new TitledPane("Edit", new Button("Edit"));
        TitledPane pane2 = new TitledPane("Save", new Button("Save"));
        TitledPane pane3 = new TitledPane("Close", new Button("Close"));
        accordion.getPanes().addAll(pane1, pane2, pane3);

        VBox vBox = new VBox(accordion);
        var myScene = new Scene(vBox, 300, 250);
       // Scene myScene = new Scene(vBox);

        primaryStage.setScene(myScene);
        primaryStage.setTitle("Accordion");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Output:

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare