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.
立即学习“Java免费学习笔记(深入)”;
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);
}
}输出:

以上就是如何创建具有两个滑块的JavaFX滑块?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号