
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
JavafxScrollpane
The JavaFX Scroll Pane control is a container and, it has 2 scroll bars around the UI component in horizontal and vertical directions, if at all if the component is larger than the visible area of the Scroll Pane area. These scroll bars are enabling the user to scroll around the UI component displayed inside the scroll pane, so we can able to see different area parts of the component can be viewed. The JavaFX package is available in javafx.scene.control.ScrollPane package.
Advantage
Scroll pane is allowed to view complete elements by vertical and horizontal scroll.
Constructor
ScrollPane():
It is a default constructor, used to create a scroll pane instance.
Frequently used Methods
-
setContent():
setContent() method in JavaFX used with ScrollPane for set any content to the ScrollPane instance.
-
setPannable(true):
setPannable(true) method in JavaFX used with ScrollPane for preview the image by clicking it and moving cursor. By default setPannable() is false.
-
setPrefSize():
setPrefSize()method in JavaFX used with ScrollPane for set the preferable size to the scroll pane.
-
setVbarPolicy():
setVbarPolicy()method in JavaFX used with ScrollPane for set the vertical policy for scroll pane.
-
setHbarPolicy():
setHbarPolicy()method in JavaFX used with ScrollPane for set the horizontal policy for scroll pane.
How to Create ScrollPane in JavaFX?
Accessing JavaFX features user-defined class must extend Application class. In JavaFX creating ScrollPane is the first step. ScrollPane can instantiate by using the new keyword.
Syntax:
ScrollPane scrollPane=new ScrollPane();
- Adding content or scroll bar policies or setPannable properties to the scrollPane is the second step.
Syntax:
scrollPane.setContent(); scrollPane.setVbarPolicy(); scrollPane.setHbarPolicy();
- Create Tile Pane or any other display(like HBox or VBox etc. as per requirement) class to add the items is the third step.
Syntax:
TilePane tPane=new TilePane (); //Gives horizontal box
- Creating a scene means screen to display output is the fourth step.
Syntax:
Scene screen = new Scene(tPane, length, width);
- Adding a Scene reference screen to the Stage object reference is the fifth step. Adding output screen to Stage. We will get this stage object reference from the start predefined JavaFX method.
Syntax:
stage.show();
Examples of JavafxScrollpane
Example #1
Adding label content to the ScrollPane and Vertical Scroll Bar Example
JavaFX Code:
package com.scrollpane; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class ScrollPaneVerticlaScrollBar extends Application { @Override public void start(Stage primaryStage) { // setting the title of application primaryStage.setTitle("ScrollPane Vertical"); // Create a ScrollPane ScrollPane scrollPane = new ScrollPane(); //creating labels for adding content Label labelContent = new Label( "DUCAT is atraining platform for IT courses like Java, PHP, CSS"); //setting preferable size(height and width) for the label content labelContent.setPrefSize(400, 100); Label labelContent1 = new Label( "DUCAT is teach you every concept in simple and clear manner"); labelContent1.setPrefSize(400, 100); Label labelContent2 = new Label( "DUCAT is offer you big discount for every course"); labelContent2.setPrefSize(400, 100); //creating VBox for adding all labels VBox vBox=new VBox(); vBox.getChildren().add(labelContent); vBox.getChildren().add(labelContent1); vBox.getChildren().add(labelContent2); // Setting the content to the ScrollPane scrollPane.setContent(vBox); // Always show vertical scroll bar for scrolling scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS); //adding scroll pane to the scene Scene scene = new Scene(scrollPane, 551, 201); primaryStage.setScene(scene); //showing the output primaryStage.show(); } public static void main(String[] args) { //invoking main method from JVM launch(args); } }
Explanation:
- We have added label content to the VBox and VBox to the ScrollPane.
- We can see in the above output, content is scrolling vertical direction because of setVPolicy().
Example #2
Adding label content to the ScrollPane and Horizontal Scroll Bar Example
JavaFX Code:
package com.scrollpane; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class ScrollPaneHorizontalScrollBar extends Application { @Override public void start(Stage primaryStage) { // setting the title of application primaryStage.setTitle("ScrollPane Vertical"); // Create a ScrollPane ScrollPane scrollPane = new ScrollPane(); //creating labels for adding content Label labelContent = new Label( "EDUCBA is online teaching platform for IT courses like Java, HTML, CSS"); //setting preferable size(height and width) for the label contentlabelContent.setPrefSize(400, 100); Label labelContent1 = new Label( "DUCAT is teach you every concept in simple and clear manner"); labelContent1.setPrefSize(400, 100); Label labelContent2 = new Label( "DUCAT is offer you big discount for every course"); labelContent2.setPrefSize(400, 100); //creating VBox for adding all labels VBox vBox=new VBox(); vBox.getChildren().add(labelContent); vBox.getChildren().add(labelContent1); vBox.getChildren().add(labelContent2); // Setting the content to the ScrollPane scrollPane.setContent(vBox); // Always show vertical scroll bar for scrolling scrollPane.setHbarPolicy(ScrollBarPolicy.ALWAYS); //adding scroll pane to the scene Scene scene = new Scene(scrollPane, 300, 400); primaryStage.setScene(scene); //showing the output primaryStage.show(); } public static void main(String[] args) { //invoking main method from JVM launch(args); } }
Explanation:
- We have added label content to the VBox and VBox to the ScrollPane.
- We can see in the above output, content is scrolling horizontal direction because of setHPolicy().