
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to create JavaFX slider with two thumbs?
In general, a slider is a component that displays a continuous range of values. This contains a track on which the numerical values are displayed. Along the track, there is a thumb pointing to the numbers. You can provide the maximum, minimum and initial values of the slider.
The slider JavaFX provides contains only one thumb if you want to create a slider with two thumbs you need to rely on an external library named org.controlsfx.control.
Following is the maven dependency for this library −
<dependency> <groupId>org.controlsfx</groupId> <artifactId>controlsfx</artifactId> <version>11.0.1</version> </dependency>
The RangeSlider class of this package is the JavaFXSlider but with two thumbs. Therefore to use it instantiate this class, add the required attributes, add it to the Node object.
Example
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; import org.controlsfx.control.RangeSlider; public class SliderTwoThumbs extends Application { public void start(Stage stage) { //Instantiating the RangeSlider class RangeSlider slider = new RangeSlider(0, 100, 10, 90); //Setting the slider properties slider.setShowTickLabels(true); slider.setShowTickMarks(true); slider.setMajorTickUnit(25); slider.setBlockIncrement(10); //VBox to arrange circle and the slider VBox vbox = new VBox(); vbox.setPadding(new Insets(75)); vbox.setSpacing(150); vbox.getChildren().addAll(slider); //Preparing the scene Scene scene = new Scene(vbox, 600, 200); stage.setTitle("Slider Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output:
- Related Articles
- How to create a JavaFX slider?
- How to set action to a slider using JavaFX?
- How to create a bubble chart with two parameters in JavaFX?
- How to change the orientation of a slider in JavaFX?
- How to change the dimensions of a slider in JavaFX?
- How to add the slider to a menu item in JavaFX?
- JavaFX example to set slider to the progress bar
- How to create Horizontal Slider in Java?
- How to create an Image Slider in ReactJS?
- How to create accordion in JavaFX?
- How to create RadioMenuItem in JavaFX?
- How to create CheckMenuItem in JavaFX?
- How to create CustomMenuItem in JavaFX?
- How to create a working slider using HTML and CSS?
- How to create a horizontal slider with custom min, max, and initial value in Java

Advertisements