×

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 Reflection

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

4 minutes read.

JavaFX Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

4 minutes read.

JavaFX Translation

In the JavaFX application, in order to apply various Translate effect, we use this class. It has the ability to Translate the given object according to the specified parameter. All...

4 minutes read.

JavaFX Bloom

In the JavaFX application, in order to apply various bloom effect, we use the Bloom class. It has the ability to bloom the colors of the shape. All methods needed...

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 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 Color Input

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

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

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX Fill Transition

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

4 minutes read.

JavaFX Pie Chart

In the JavaFX application, in order to create Pie Chart, the PieChart class is used. The Pie Chart allows us to plot data along with the sectors of the circle....

3 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 Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

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 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 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 Line Chart

In the JavaFX application, in order to create a Line Chart, LineChart class is used. The LineChart allows us to plot markers point according to the entities on number axes....

4 minutes read.

JavaFX Event Handling

JavaFX gives way to handle various events in web application, desktop applications and graphical applications. In the JavaFX application, in order to allow user to interact with application various events...

4 minutes read.

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

5 minutes read.