×

JavaFX ScrollBar

In the JavaFX application, in order to scroll over a range of values, ScrollBar is used. It is used to view long page contents. In order to use ScrollBar in JavaFX, javafx.scene.control.ScrollBar class is used.

JavaFX Horizontal ScrollBar:

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ScrollBar;
import javafx.scene.layout.StackPane;


  
public class ScrollBarUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
         ScrollBar newcroll = new ScrollBar();  
         StackPane pane = new StackPane();  
         pane.getChildren().add( newcroll );  
         Scene scene = new Scene( pane, 400, 200 );  
         primaryStage.setScene( scene );  
         primaryStage.setTitle(" JavaFX horizontal ScrollBar Example ");  
         primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the ScrollBar in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ScrollBar, javafx.scene.layout.StackPane.

Then we have created one class named ScrollBarUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold horizontal ScrollBar, a StackPane object is created which is then passed to the Scene class object.

The ScrollBar is created with its constructor.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX horizontal ScrollBar Example”. Also, it displays Simple ScrollBar covering all horizontal space.

JavaFX ScrollBar

JavaFX Vertical ScrollBar:

Example:

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ScrollBar;
import javafx.scene.layout.StackPane;


  
public class ScrollBarUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    ScrollBar newcroll = new ScrollBar();  
    newcroll.setOrientation(Orientation.VERTICAL);  
         StackPane pane = new StackPane();  
         pane.getChildren().add( newcroll );  
         Scene scene = new Scene( pane, 400, 200 );  
         primaryStage.setScene( scene );  
         primaryStage.setTitle(" JavaFX vertical ScrollBar Example ");  
         primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the vertical ScrollBar in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ScrollBar, javafx.scene.layout.StackPane.

Then we have created one class named ScrollBarUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold vertical ScrollBar, a StackPane object is created which is then passed to the Scene class object.

The ScrollBar is created with its constructor. And then setOrientation() method with Orientation. The VERTICAL argument is called on scroll bar object.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX vertical ScrollBar Example”. Also, it displays vertical ScrollBar covering all vertical space.

JavaFX ScrollBar

JavaFX ScrollBar with min, max and current value:

Example:

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ScrollBar;
import javafx.scene.layout.StackPane;


  
public class ScrollBarUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    ScrollBar newcroll = new ScrollBar();  
    newcroll.setMin(0);  
    newcroll.setMax(200);  
    newcroll.setValue(80);  
    newcroll.setOrientation(Orientation.VERTICAL);  
    newcroll.setUnitIncrement(10);  
    newcroll.setBlockIncrement(10);          
    StackPane pane = new StackPane();  
         pane.getChildren().add( newcroll );  
         Scene scene = new Scene( pane, 400, 200 );  
         primaryStage.setScene( scene );  
         primaryStage.setTitle(" JavaFX vertical ScrollBar with current value specified Example ");  
         primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the vertical ScrollBar with current value specified in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ScrollBar, javafx.scene.layout.StackPane, javafx.geometry.Orientation.

Then we have created one class named ScrollBarUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold vertical ScrollBar with the current value, min, max value specified, StackPane object is created which is then passed to Scene class object.

The ScrollBar is created with its constructor. And then setOrientation() method with Orientation. The VERTICAL argument is called on scroll bar object. The setMin(), setMax(), setValue() method is called with value passed to it to set min, max and current value specified.

The stage is prepared, the title is set and the show() method is called to display output. The launch(args) method is called. In output Frame like container is displayed with a title, "JavaFX vertical ScrollBar with the current value specified Example”. Also, it displays vertical ScrollBar covering all vertical space and current value specified to 80 unit.

JavaFX ScrollBar

Related Topics

JavaFX Line

In the JavaFX application, in order to draw a line, the Line class is used. The line allows us to join any two points with x and y coordinates in...

3 minutes read.

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for...

4 minutes read.

JavaFX Image Input

In the JavaFX application, in order to apply various image input effect, we use the ImageInput class. It has the ability to fill the specified shape with a given image...

4 minutes read.

JavaFX CheckBox

In the JavaFX application, to get the user information in the form of choices from the user, a form is created using checkboxes that allow the user to select two...

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

4 minutes read.

JavaFX Cylinder

In the JavaFX application, in order to draw a Cylinder, the Cylinder class is used. The Cylinder allows us to form a 3D shape having rectangular faces and a straight...

4 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Scale Transition

In the JavaFX application, in order to generate the scale transition, we have to apply scale transition on any particular shape. It has the ability to scale the shape along...

4 minutes read.

JavaFX Stroke Transition

In the JavaFX application, in order to generate the stroke transition, we have to apply stroke transition on any particular shape. It has the ability to give different color strokes...

4 minutes read.

JavaFX Shear

In the JavaFX application, in order to apply various shear effect, we use this class. It has the ability to shear the given object along the x or y axis....

3 minutes read.

JavaFX HBox

In the JavaFX application, in order to set HBox as a layout, the HBox class is used. The HBox layout allows us to arrange the components in one row. All...

3 minutes read.

JavaFX Bubble Chart

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for this...

4 minutes read.

JavaFX TilePane

In the JavaFX application, in order to set TilePane as a layout, the TilePane class is used. The TilePane layout allows us to arrange the components in the same sized...

4 minutes read.

JavaFX Tutorial

Introduction of JavaFX: The most popular applications called Rich Internet Application are build using the JavaFX. This application can run across many platforms. Various devices such as mobile, computers, and tablets...

4 minutes read.

JavaFX Inline Styles

In the JavaFX application, in order to apply various Inline css effect we will use the various css classes available in the JavaFX. It is used to apply the various...

4 minutes read.

JavaFX Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for...

5 minutes read.

JavaFX Button Styling

 In the JavaFX application, we can apply CSS styling to buttons in various ways. We can change the size of the button as well as border colour, text colour can...

3 minutes read.

JavaFX RadioButton

In the JavaFX application, to get the user information in the form of choice from the user, a form is created using radio buttons that allow the user to select...

3 minutes read.