JavaFX Titled Pane


JavaFX Titled Pane Tutorials:

The Titled Pane is a panel with title and this panel can be opened and closed.

We can add any node to the pane so it is used to encapsulate nodes.

Constructors :

  • TitledPane()Creates a new TitledPane with no title or content.
  • TitledPane(String title, Node content)Creates a new TitledPane with a title and content.

Creating Titled Pane :

TitledPane titledPane = new TitledPane();

Create a button

Button button =new Button(" NEW BUTTON ");

Add button to the titledPane



Sets the expanded state of the TitledPane.

Example using titled pane:

package javafxtuts;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TitledPane;
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 titledPane = new TitledPane();
      //to create a new button 
       Button button =new Button(" NEW BUTTON ");
        // to Sets the expanded state of the TitledPane

      VBox root =new VBox();
      root.setPadding(new Insets(20, 10, 10, 10));
        Scene scene = new Scene(root, 250, 200);

Output :

Explanation of titled pane example :

  • Creating a new TitledPane asTitledPane titledPane = new TitledPane();
  • Button button =new Button(" NEW BUTTON ");It create a new button.
  • Set the node using setContent() to the TitledPane() AStitledPane.setContent(button);
  • titledPane.setExpanded(true);It expands the titledPane.

Leave A Reply