如何创建具有两个滑块的JavaFX滑块?

2023年 8月 29日 29.6k 0

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.

如何创建具有两个滑块的JavaFX滑块?

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 −

org.controlsfx
controlsfx
11.0.1

登录后复制

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);
}
}

登录后复制

输出:

如何创建具有两个滑块的JavaFX滑块?

以上就是如何创建具有两个滑块的JavaFX滑块?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论