JavaFX Accordion


JavaFX Accordion Tutorials:

JavaFX Accordion UI control is a group of TitledPane(multiple TitledPane).


  • Accordion()
    Creates a new Accordion with no TitledPanes.
  • Accordion(TitledPane… titledPanes)
    Creates a new Accordion with the given TitledPanes showing within it.

Creating Accordion :

Accordion accordion = new Accordion();

getPanes() is used to get panes to the accordion.


Example of accordion:

package javafxtuts;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Javafxtuts extends Application {

  public static void main(String[] args) {

  public void start(Stage stage) {
      TitledPane TitlePane = new TitledPane();
//Creating a GridPane layout
GridPane grid = new GridPane();
grid.setPadding(new Insets(5, 5, 5, 5));
grid.add(new Label("First Name: "), 0, 0);
grid.add(new TextField(), 1, 0);        
TitlePane.setText("First TitledPane");

TitledPane titlePane = new TitledPane();
titlePane.setText("Second TitledPane");
titlePane.setContent(new Button(" NEW BUTTON "));
      VBox root =new VBox();
      root.setPadding(new Insets(20, 10, 10, 10));
        Scene scene = new Scene(root, 300, 200);

Output :

Explanation of accordion example:

  • Creating new TitledPane of name TitledPane AS

    TitledPane TitlePane = new TitledPane();
  • grid.add(new Label("First Name: "), 0, 0);
    It put the FIrst Name label at 0th column and 0th row.
  • Creating Accordion AS
    Accordion accordion = new Accordion();
  • accordion.getPanes().addAll(TitlePane,titlePane);
    It add both TitledPanes to the accordion.

Leave A Reply