Quick Contact

    Hibernate

    JavaFXTabPane

    TabPane in JavaFX is used to create tabs in standalone applications like mobile apps, PC installation software etc. TabPane class in JavaFX can create any number of tabs using TabPane() constructor. Each TabPane has a specific index position for recognizing the exact tabs. TabPane tab index positions used for switching between tabs for adding the functionalities inaccurate tabs. JavaFXTabPane class available in javafx.scene.control.TabPane package.

    What can we do with TabPane in JavaFX?

    TabPane in JavaFX is used for creating multiple tabs for adding different content in the tabs.

    Constructors:

    • TabPane():

      It is default constructor, used to create Tab pane instance.

    • TabPane(tab1, tab2, tab3,……):

      It is parameterized constructor, it accepts multiple tab values at a time.

    Frequently used Methods:
    1. setSide(Side s):

      setSide() method used to set the tab at index position.

    2. getSide():

      getSide() method gives current position of tab.

    3. getTabs():

      getTabs() gives the tabs from Tab pane.

    4. setSelectionModel(SingleSelectionModel s):

      setSelectionModel() method used to set the selection model of the tab pane.

    5. getSelectionModel():

      setSelectionModel() method used to get the selection model of the tab pane.

    6. setTabMaxHeight(double d):

      setTabMaxHeight() method set the max height of the tab pane.

    7. getTabMaxHeight():

      getTabMaxHeight() method gives you max height of the tab pane.

    8. setTabMinHeight(double d):

      setTabMinHeight() method set the min height of the tab pane.

    9. getTabMinHeight():

      getTabMinHeight() method gives you min height of the tab pane.

    10. setTabMaxWidth(double d):

      setTabMaxHeight() method set the max width of the tab pane.

    11. getTabMaxWidth():

      getTabMaxWidth() method gives you max width of the tab pane.

    12. setTabMinWidth(double d):

      setTabMinHeight() method set the min width of the tab pane.

    13. getTabMinWidth():

      getTabMinWidth() method gives you max width of the tab pane.

    How to Create ScrollPane in JavaFX?
    1. Accessing JavaFX features user defined class must extends Application class.
    2. In JavaFX creating TabPane is first step. TabPane can instantiate by using new keyword.
    3. Syntax:

      TabPane tabPane=new TabPane ();

      • Creating Tabs and adding tabs to the TabPane is second step.

      Syntax:

      Tab tab=new Tab(“Some content”);

      tabPane.getTabs().add(tab);

    4. Create VBox or any other display(like TilePane or HBox etc. as per requirement) class to add the items is third step.
    5. Syntax:

      VBox vBox=new VBox (tabPane); //Gives vertical box

    6. Creating a scene means screen to display output is the fourth step.
    7. Syntax:

      Scene screen = new Scene(vBox, length, width);

    8. Adding Scene reference screen to the Stage object reference is fifth step. Adding output screen to Stage. We will get this stage object reference from start predefined JavaFX method.
    9. Syntax:

      stage.setScene(screen);

    10. At last display output screen by showing stage reference with the show () method.
    11. Syntax:

      stage.show();

    Examples of JavaFXTabPane

    Below are the examples of JavaFXTabPane:

    Example #1

    Adding tabs to tab pane.

    Code:

    package com.tabpane;
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Tab;
    import javafx.scene.control.TabPane;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class TabPaneTabs extends Application {
    @Override
    public void start(Stage primaryStage) {
    // setting the title of application
    primaryStage.setTitle("TabPane Tabs");
    // Create a TabPane
    TabPane tabPane = new TabPane();
    //creating Tabs for adding content
    Tab ducatTab=new Tab("DUCAT");
    Tab coursesTab=new Tab("Courses");
    Tab feeTab=new Tab("Fee of Courses");
    Tab aboutTab=new Tab("About DUCAT");
    //adding tabs to tabpane
    tabPane.getTabs().add(ducatTab);
    tabPane.getTabs().add(coursesTab);
    tabPane.getTabs().add(feeTab);
    tabPane.getTabs().add(aboutTab);
    //creating VBox for adding tab pane
    VBox vBox=new VBox(tabPane);
    //adding scroll pane to the scene
    Scene scene = new Scene(vBox, 401, 401);
    primaryStage.setScene(scene);
    //showing the output
    primaryStage.show();
    }
    public static void main(String[] args) {
    //invoking main method from JVM
    launch(args);
    }
    }
    

    Example #2

    Adding content to the tabs.

    Code:

    package com.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 AddingContentToTabs extends Application {
    @Override
    public void start(Stage primaryStage) {
    // setting the title of application
    primaryStage.setTitle("Adding Content to Tabs");
    // Create a TabPane
    TabPane tabPane = new TabPane();
    // creating label for adding content to tabs
    Label ducatLabel = new Label("\t\t\tDUCAT is online courses portal.");
    Label courseLable = new Label("\t\t\tHTML || CSS || JavaScript || Java || Python");//\t is for tab space
    Label feeLabel = new Label("\t\t\tPrices are between 1000/- to 5000/-");
    Label aboutDUCATLabel = new Label("\t\t\tDUCAT has strong content to teach IT courses easily.");
    // creating Tabs for adding content
    Tab ducatTab = new Tab("DUCAT");
    Tab coursesTab = new Tab("Courses");
    Tab feeTab = new Tab("Fee of Courses");
    Tab aboutTab = new Tab("About DUCAT");
    // adding content to tabs
    ducatTab.setContent(ducatLabel);
    coursesTab.setContent(courseLable);
    feeTab.setContent(feeLabel);
    aboutTab.setContent(aboutDUCATLabel);
    // adding tabs to tabpane
    tabPane.getTabs().add(educbaTab);
    tabPane.getTabs().add(coursesTab);
    tabPane.getTabs().add(feeTab);
    tabPane.getTabs().add(aboutTab);
    // creating VBox for adding tab pane
    VBox vBox = new VBox(tabPane);
    // adding scroll pane to the scene
    Scene scene = new Scene(vBox, 401, 401);
    primaryStage.setScene(scene);
    // showing the output
    primaryStage.show();
    }
    public static void main(String[] args) {
    // invoking main method from JVM
    launch(args);
    }
    }
    

    Apply now for Advanced Java Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.