Home > Java > javaTutorial > How to create a JavaFX slider with two sliders?

How to create a JavaFX slider with two sliders?

PHPz
Release: 2023-08-25 16:05:09
forward
632 people have browsed it

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.

How to create a JavaFX slider with two sliders?

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>
Copy after login

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);
   }
}
Copy after login

输出:

How to create a JavaFX slider with two sliders?

The above is the detailed content of How to create a JavaFX slider with two sliders?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template