You are reading the article How To Create Scrollpane In Javafx? updated in October 2023 on the website Restaurant12h.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 How To Create Scrollpane In Javafx?
Introduction to JavaFX TabPaneTabPane 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. JavaFX TabPane class available in javafx.scene.control.TabPane package.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
What can we do with TabPane in JavaFX? 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.
Methods
setSide(Side s): setSide() method used to set the tab at index position.
getSide(): getSide() method gives current position of tab.
getTabs(): getTabs() gives the tabs from Tab pane.
setSelectionModel(SingleSelectionModel s): setSelectionModel() method used to set the selection model of the tab pane.
getSelectionModel(): setSelectionModel() method used to get the selection model of the tab pane.
setTabMaxHeight(double d): setTabMaxHeight() method set the max height of the tab pane.
getTabMaxHeight(): getTabMaxHeight() method gives you max height of the tab pane.
setTabMinHeight(double d): setTabMinHeight() method set the min height of the tab pane.
getTabMinHeight(): getTabMinHeight() method gives you min height of the tab pane.
setTabMaxWidth(double d): setTabMaxHeight() method set the max width of the tab pane.
getTabMaxWidth(): getTabMaxWidth() method gives you max width of the tab pane.
setTabMinWidth(double d): setTabMinHeight() method set the min width of the tab pane.
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.
TabPane tabPane=new TabPane ();
Creating Tabs and adding tabs to the TabPane is second step.
Tab tab=new Tab("Some content"); tabPane.getTabs().add(tab);3. Create VBox or any other display(like TilePane or HBox etc. as per requirement) class to add the items is third step.
VBox vBox=new VBox (tabPane);4. Creating a scene means screen to display output is the fourth step.
Scene screen = new Scene(vBox, length, width);5. 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.
stage.setScene(screen);6. At last display output screen by showing stage reference with the show () method.
stage.show(); Examples of JavaFX TabPaneBelow are the examples of JavaFX TabPane:
Example #1Adding 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) { primaryStage.setTitle("TabPane Tabs"); TabPane tabPane = new TabPane(); Tab educbaTab=new Tab("EDUCBA"); Tab coursesTab=new Tab("Courses"); Tab feeTab=new Tab("Fee of Courses"); Tab aboutTab=new Tab("About EDUCBA"); tabPane.getTabs().add(educbaTab); tabPane.getTabs().add(coursesTab); tabPane.getTabs().add(feeTab); tabPane.getTabs().add(aboutTab); VBox vBox=new VBox(tabPane); Scene scene = new Scene(vBox, 401, 401); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }Output:
As you can see in the above output, we have added tabs to the tab pane with the help of VBox.
Example #2Adding 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) { primaryStage.setTitle("Adding Content to Tabs"); TabPane tabPane = new TabPane(); Label educbaLabel = new Label("tttEDUCBA is online courses portal."); Label feeLabel = new Label("tttPrices are between 1000/- to 5000/-"); Label aboutEDUCBALabel = new Label("tttEDUCBA has strong content to teach IT courses easily."); Tab educbaTab = new Tab("EDUCBA"); Tab coursesTab = new Tab("Courses"); Tab feeTab = new Tab("Fee of Courses"); Tab aboutTab = new Tab("About EDUCBA"); educbaTab.setContent(educbaLabel); coursesTab.setContent(courseLable); feeTab.setContent(feeLabel); aboutTab.setContent(aboutEDUCBALabel); tabPane.getTabs().add(educbaTab); tabPane.getTabs().add(coursesTab); tabPane.getTabs().add(feeTab); tabPane.getTabs().add(aboutTab); VBox vBox = new VBox(tabPane); Scene scene = new Scene(vBox, 401, 401); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }Output:
As you can see in the above output, we have added tabs, label content to the tabs and then tabs to the tab pane with the help of VBox.
Example #3Setting minimum and maximum width and height to the tab pane.
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 TabsHeigthWidthAlignment extends Application { @Override public void start(Stage primaryStage) { primaryStage.setTitle("Adding Content to Tabs"); TabPane tabPane = new TabPane(); Label educbaLabel = new Label("tttEDUCBA is online courses portal."); Label feeLabel = new Label("tttPrices are between 1000/- to 5000/-"); Label aboutEDUCBALabel = new Label("tttEDUCBA has strong content to teach IT courses easily."); Tab educbaTab = new Tab("EDUCBA"); Tab coursesTab = new Tab("Courses"); Tab feeTab = new Tab("Fee of Courses"); Tab aboutTab = new Tab("About EDUCBA"); tabPane.setTabMinWidth(30); tabPane.setTabMinHeight(30); tabPane.setTabMaxWidth(100); tabPane.setTabMaxHeight(100); educbaTab.setContent(educbaLabel); coursesTab.setContent(courseLable); feeTab.setContent(feeLabel); aboutTab.setContent(aboutEDUCBALabel); tabPane.getTabs().add(educbaTab); tabPane.getTabs().add(coursesTab); tabPane.getTabs().add(feeTab); tabPane.getTabs().add(aboutTab); VBox vBox = new VBox(tabPane); Scene scene = new Scene(vBox, 401, 401); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }Output:
Explanation:
As you can see in the above code tabPane.setTabMinWidth(30), tabPane.setTabMinHeight(30), tabPane.setTabMaxWidth(100), tabPane.setTabMaxHeight(100) methods set the maximum and minimum height and width to the tab pane.
ConclusionTabPane in JavaFX is used to add tabs for adding content to the tabs. Tabs are used for differentiate one content to the other content by keeping the content in different tabs.
Recommended ArticleThis is a guide to JavaFX TabPane. Here we discuss what can we do with TabPane in JavaFX and how to Create ScrollPane along with Code Implementation and Output. you can also go through our suggested articles to learn more –
You're reading How To Create Scrollpane In Javafx?
Update the detailed information about How To Create Scrollpane In Javafx? on the Restaurant12h.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!