×

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 StackPane

In the JavaFX application, in order to set Stack Pane as a layout, the StackPane class is used. The StackPane layout allows us to arrange the components in the stack...

4 minutes read.

JavaFX HyperLink

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To...

4 minutes read.

JavaFX Convenience Methods

The JavaFX allows us to use various convenience methods to handle events on various nodes in JavaFX applications. The convenience methods provides us easy and effective way to add any...

4 minutes read.

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

4 minutes read.

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...

4 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 minutes read.

JavaFX Sequential Transition

In the JavaFX application, in order to generate the sequential transition, we have to apply sequential transition on any particular shape. It has the ability to execute multiple transactions sequentially...

4 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 UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX Sphere

In the JavaFX application, in order to draw a Sphere, the Sphere class is used. The Sphere allows us to form a 3D shape having circular faces. All methods needed...

4 minutes read.

JavaFX Architecture

JavaFX architecture consists of many built-in components such as JavaFX public API, Scene Graph, Quantum Toolkit, Prism, Glass windowing toolkit, web view, media engines. These components help to develop rich...

3 minutes read.

JavaFX Bar Chart

In the JavaFX application, in order to create Bar Chart, the BarChart class is used. The Bar Chart allows us to plot data along different bars to show the scales...

4 minutes read.

JavaFX Light Spot

In the JavaFX application, in order to apply various Light Spot effect from a single source, we use this class. It has the ability to apply light from all the...

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 Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX Inner Shadow

In the JavaFX application, in order to apply various Inner Shadow effect, we use this class. It has the ability to create the inner shadow of the given object. This...

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 Lighting

In the JavaFX application, in order to apply various Lighting effect from a single source, we use this class. It has the ability to lighten a node from a given...

4 minutes read.