javafx tabpane

www.igi‮oc.aeditf‬m

In JavaFX, the TabPane class is a layout container that allows the user to switch between a group of tabs, where each tab contains its own content. You can use it to create multi-page interfaces, where each tab represents a different view or task.

Here's an example of how to create and use a TabPane:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class MyJavaFXApp extends Application {

    @Override
    public void start(Stage primaryStage) {
        // Create a TabPane object
        TabPane tabPane = new TabPane();
        
        // Create some tabs and add them to the TabPane
        Tab tab1 = new Tab("Tab 1");
        Label label1 = new Label("This is the content of Tab 1.");
        VBox vbox1 = new VBox(label1);
        tab1.setContent(vbox1);
        tabPane.getTabs().add(tab1);
        
        Tab tab2 = new Tab("Tab 2");
        Label label2 = new Label("This is the content of Tab 2.");
        VBox vbox2 = new VBox(label2);
        tab2.setContent(vbox2);
        tabPane.getTabs().add(tab2);
        
        // Create a scene and set it on the stage
        Scene scene = new Scene(tabPane, 300, 200);
        primaryStage.setScene(scene);

        // Show the stage
        primaryStage.show();
    }

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

In this example, we create a TabPane object and add some tabs to it, using the Tab class. We set the content of each tab to a Label object, which is wrapped in a VBox to enable additional layout options. We use the setContent() method of the Tab class to set the content of each tab.

The TabPane enables the user to switch between the tabs by clicking on them. The TabPane also provides various layout options for the tabs, such as placing them at the top, bottom, left, or right of the container. You can customize the appearance and behavior of the tabs using various properties and methods of the TabPane and Tab classes.